Example usage for org.joda.time LocalDate LocalDate

List of usage examples for org.joda.time LocalDate LocalDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate LocalDate.

Prototype

public LocalDate(int year, int monthOfYear, int dayOfMonth) 

Source Link

Document

Constructs an instance set to the specified date and time using ISOChronology.

Usage

From source file:com.rappsantiago.weighttracker.progress.AddEditProgressFragment.java

License:Apache License

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    LocalDate date = new LocalDate(year, monthOfYear + 1, dayOfMonth);
    mDateInMillis = date.toDate().getTime();
    mLblDate.setText(DisplayUtil.getReadableDate(mDateInMillis));
}

From source file:com.receipts.backingbeans.StoreView.java

public void importStores(FileUploadEvent event) {
    int userId = (int) event.getComponent().getAttributes().get("userId");
    UploadedFile zipFile = event.getFile();

    String insertStoresSql = "insert into stores (store_id, store_date, user_id) values (?, ?, ?)";
    String selectStoresSql = "select id from stores where store_id = ? and store_date = ?";
    String insertReceiptsSql = "insert into receipts (store_fk, user_id, img_name) values (?, ?, ?)";
    try (Connection conn = DbUtils.getDbConnection()) {
        try (ZipInputStream zin = new ZipInputStream(new BufferedInputStream(zipFile.getInputstream()));
                PreparedStatement insertStoresPs = conn.prepareStatement(insertStoresSql);
                PreparedStatement selectStoresPs = conn.prepareStatement(selectStoresSql);
                PreparedStatement insertReceiptsPs = conn.prepareStatement(insertReceiptsSql)) {
            ZipEntry entry;//from   w  w w .j  av  a  2s  .  c om

            conn.setAutoCommit(false);

            while ((entry = zin.getNextEntry()) != null) {
                String entryName = entry.getName();
                boolean isDirectory = entry.isDirectory();

                if (isDirectory) {
                    String storeId = entryName.split("_")[0];
                    String storeDay = entryName.split("_")[1];
                    String storeMonth = entryName.split("_")[2];
                    String storeYear = entryName.split("_")[3].substring(0,
                            entryName.split("_")[3].length() - 1);

                    LocalDate storeDate = new LocalDate(Integer.parseInt(storeYear),
                            Integer.parseInt(storeMonth), Integer.parseInt(storeDay));

                    insertStoresPs.setString(1, storeId);
                    insertStoresPs.setDate(2,
                            new java.sql.Date(storeDate.toDateTimeAtStartOfDay().getMillis()));
                    insertStoresPs.setInt(3, userId);

                    insertStoresPs.executeUpdate();
                } else {
                    String storeData = entryName.split("/")[0];
                    String fileName = entryName.split("/")[1];

                    if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".jpeg")
                            || fileName.toLowerCase().endsWith(".png")
                            || fileName.toLowerCase().endsWith(".gif") || fileName.endsWith(".tiff")) {
                        String storeId = storeData.split("_")[0];
                        String storeDay = storeData.split("_")[1];
                        String storeMonth = storeData.split("_")[2];
                        String storeYear = storeData.split("_")[3];

                        LocalDate storeDate = new LocalDate(Integer.parseInt(storeYear),
                                Integer.parseInt(storeMonth), Integer.parseInt(storeDay));

                        selectStoresPs.setInt(1, Integer.parseInt(storeId));
                        selectStoresPs.setDate(2,
                                new java.sql.Date(storeDate.toDateTimeAtStartOfDay().getMillis()));

                        int storePK = -1;
                        try (ResultSet rs = selectStoresPs.executeQuery()) {
                            while (rs.next()) {
                                storePK = rs.getInt("id");
                            }
                        }

                        //                            insertReceiptsPs.setBlob(1, zin, entry.getSize());
                        insertReceiptsPs.setInt(1, storePK);
                        insertReceiptsPs.setInt(2, userId);
                        insertReceiptsPs.setString(3, fileName);

                        insertReceiptsPs.executeUpdate();
                    }
                }
            }

            conn.commit();

            allStores = storesService.loadAllStores();
            conn.setAutoCommit(true);
        } catch (Exception ex) {
            conn.rollback();
            conn.setAutoCommit(true);

            ex.printStackTrace();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:com.scit.spring.AppMain.java

public static void main(String args[]) {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
    String names[] = context.getBeanDefinitionNames();
    for (String name : names) {
        System.out.println(name);
    }//  w  ww.  j  a  v a  2  s.c o  m
    EmployeeService service = (EmployeeService) context.getBean("employeeServiceImpl");

    /*
     * Create Employee1
     */
    Employee employee1 = new Employee();
    employee1.setName("Han Yenn");
    employee1.setJoiningDate(new LocalDate(2010, 10, 10));
    employee1.setSalary(new BigDecimal(10000));
    employee1.setSsn("ssn00000001");

    /*
     * Create Employee2
     */
    Employee employee2 = new Employee();
    employee2.setName("Dan Thomas");
    employee2.setJoiningDate(new LocalDate(2012, 11, 11));
    employee2.setSalary(new BigDecimal(20000));
    employee2.setSsn("ssn00000002");

    /*
     * Persist both Employees
     */
    service.ins(employee1);
    service.ins(employee2);

    /*
     * Get all employees list from database
     */
    List<Employee> employees = service.selTodo();
    for (Employee emp : employees) {
        System.out.println(emp);
    }

    /*
     * delete an employee
     */
    service.deleteEmployeeBySsn("ssn00000002");

    /*
     * update an employee
     */

    Employee employee = service.findBySsn("ssn00000001");
    employee.setSalary(new BigDecimal(50000));
    service.upd(employee);

    /*
     * Get all employees list from database
     */
    List<Employee> employeeList = service.selTodo();
    for (Employee emp : employeeList) {
        System.out.println(emp);
    }

    context.close();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the month name from the encodedDate,
  * 'January' ,'February', etc.//from   www . j av  a 2s .c  o m
 *
 * @param encodedDate   the encoded date
 * @return             month name.
 */
static String getMonthName(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.monthOfYear().getAsText();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the week of year from the encodedDate,
  * 1-52.//from www . ja va  2 s . co  m
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static int getWeek(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.weekOfWeekyear().get();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the day of week from the encodedDate,
  * 1-7.//w  w  w .  j  a  v  a 2 s .  co  m
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static int getWeekDay(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.dayOfWeek().get();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the week day name from the encodedDate,
  * 'Monday' ,'Tuesday', etc./*from   www  .  j a v a 2  s  .c o m*/
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static String getWeekDayName(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.dayOfWeek().getAsText();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the day of year from the encodedDate,
 * 1-366.//  w  w  w  .  j a  va2 s  .  com
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static int getDayOfYear(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.dayOfYear().get();
}

From source file:com.springsource.greenhouse.signup.SignupForm.java

License:Apache License

/**
 * Creates a Person record from this SignupForm.
 * A Person is used as input to {@link AccountRepository} to create a new member Account.
 *///  w w w.  j a v a2  s  .c om
public Person createPerson() {
    return new Person(firstName, lastName, email, password, gender, new LocalDate(year, month, day));
}

From source file:com.stitchgalaxy.domain.service.SitchGalaxyService.java

@Transactional(rollbackFor = Exception.class)
public void addProduct() {
    Product p = new Product();
    p.setBlocked(Boolean.TRUE);//from   w w w .  j  a  v a  2 s.co  m
    p.setPrice(BigDecimal.ZERO);
    p.setDate(new LocalDate(2014, 1, 1));
    productRepository.save(p);
}