List of usage examples for org.joda.time LocalDate fromDateFields
@SuppressWarnings("deprecation") public static LocalDate fromDateFields(Date date)
java.util.Date
using exactly the same field values. From source file:graphene.util.time.JodaTimeUtil.java
License:Apache License
public static LocalDate toLocalDate(final java.util.Date d) { // TODO - confirm this conversion always works, esp. across timezones final LocalDate ld = (d == null ? null : LocalDate.fromDateFields(d)); return ld;/* ww w .ja v a 2s . c om*/ }
From source file:gt.org.ms.api.utils.EntitiesHelper.java
public static Integer getAge(Date birthDate) { return Years.yearsBetween(LocalDate.fromDateFields(birthDate), LocalDate.fromDateFields(Calendar.getInstance().getTime())).getYears(); }
From source file:gt.org.ms.controller.personas.handlers.PersonasBaseHandler.java
public void setDatosGeneralesByLector(Persona currentPersona, RequestCreatePersonaDto r) { if (isNull(r.getFoto()) || r.getFoto().isEmpty()) { throw ExceptionsManager.newValidationException("foto", "La fotografia es requerida!"); }/* w w w .j a v a 2 s .c o m*/ if (!isNull(r.getFechaNacimientoTexto()) && !r.getFechaNacimientoTexto().isEmpty()) { currentPersona.setFechaNacimiento(parseFechaDPI(r.getFechaNacimientoTexto())); } else { throw ExceptionsManager.newValidationException("fecha_nacimiento", "fecha de nacimiento es requerida!"); } currentPersona.setEdad(Years.yearsBetween(LocalDate.fromDateFields(currentPersona.getFechaNacimiento()), LocalDate.fromDateFields(Calendar.getInstance().getTime())).getYears()); if (!isNull(r.getFkMunicipioNacimientoNombre()) && !r.getFkMunicipioNacimientoNombre().isEmpty()) { currentPersona.setFkMunicipioNacimiento( getAreaByNombreAndTipo(r.getFkMunicipioNacimientoNombre(), C.CAT_AG_TIPO_MUNICIPIOS).getId()); } else { throw ExceptionsManager.newValidationException("municipio_nacimiento", "municipio nacimiento es requerido!"); } if (!isNull(r.getFkMunicipioCedulaNombre()) && !r.getFkMunicipioCedulaNombre().isEmpty()) { currentPersona.setFkMunicipioCedula( getAreaByNombreAndTipo(r.getFkMunicipioCedulaNombre(), C.CAT_AG_TIPO_MUNICIPIOS).getId()); } if (!isNull(r.getFkMunicipioVecindadNombre()) && !r.getFkMunicipioVecindadNombre().isEmpty()) { currentPersona.setFkMunicipioVecindad( getAreaByNombreAndTipo(r.getFkMunicipioVecindadNombre(), C.CAT_AG_TIPO_MUNICIPIOS).getId()); } else { throw ExceptionsManager.newValidationException("municipio_vecindad", "municipio vecindad es requerido!"); } if (!isNull(r.getFkNacionalidadNombre()) && !r.getFkNacionalidadNombre().isEmpty()) { currentPersona.setFkNacionalidad( getCatalogoByNombreAndTipo(r.getFkNacionalidadNombre(), C.CAT_GEN_NACIONALIDAD).getId()); } else { throw ExceptionsManager.newValidationException("nacionalidad", "Nacionalidad es requerido!"); } DpiDto dpiDto; if (!isNull(dpiDto = r.getDpi())) { if (!isNull(dpiDto.getFechaEmisionTexto()) && !isNull(dpiDto.getFechaVencimientoTexto())) { dpiDto.setFechaEmision(parseFechaDPI(dpiDto.getFechaEmisionTexto())); dpiDto.setFechaVencimiento(parseFechaDPI(dpiDto.getFechaVencimientoTexto())); r.setDpi(dpiDto); } else if (isNull(dpiDto.getFechaVencimiento()) || isNull(dpiDto.getFechaEmision())) { throw ExceptionsManager.newValidationException("dpi_datos", new String[] { "fechas_dpi,Debe ingresar datos de fecha vencimiento y emision del DPI" }); } } else { throw ExceptionsManager.newValidationException("dpi", new String[] { "dpi,Lectura de DPI es invalida, datos del DPI son requeridos!" }); } }
From source file:javaapplication5.NewJFrame.java
private boolean validateDateCompensation() { boolean result = true; try {/*from w w w.j ava 2 s .com*/ //campos text no podem estar vazios if ((dtBeginCompensation.getText().trim().length() < 0) || (dtEndCompensation.getText().trim().length() < 0)) { result = false; } //validar datas if (result) { //captura datas Date beginDt = null, endDate = null; try { beginDt = new SimpleDateFormat("dd/MM/yyyy").parse(dtBeginCompensation.getText().trim()); endDate = new SimpleDateFormat("dd/MM/yyyy").parse(dtEndCompensation.getText().trim()); } catch (Exception e) { result = false; } if (result) { //mximo dois anos de intervalo int yearsQtty = LocalDate.fromDateFields(endDate).getYear() - LocalDate.fromDateFields(beginDt).getYear(); if (yearsQtty < 0 || yearsQtty > 2) { result = false; } } //segunda data no pode ser anterior a primeira if (result) { if (endDate.compareTo(beginDt) < 0) { result = false; } } } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:javaapplication5.NewJFrame.java
private void saveCompensation() { try {/*from w w w . ja va 2 s . c o m*/ if (validateDateCompensation()) { Configuration config = configurationDao.getConfiguration(); Compensation comp = new Compensation(); //carregar datas Date beginDt, endDate; beginDt = new SimpleDateFormat("dd/MM/yyyy").parse(dtBeginCompensation.getText().trim()); endDate = new SimpleDateFormat("dd/MM/yyyy").parse(dtEndCompensation.getText().trim()); //preencher compensation comp.setBeginDate(LocalDate.fromDateFields(beginDt)); comp.setEndDate(LocalDate.fromDateFields(endDate)); comp.setActive(cbCompensation.isSelected()); //salvando config.setCompensation(comp); configurationDao.setConfiguration(config); } } catch (Exception e) { e.printStackTrace(); } }
From source file:jiajiechen.countdown.DialogNew.java
License:Open Source License
private void submitActionPerformed(ActionEvent evt) { setDateTime(LocalDate.fromDateFields(datePick.getDate()).toDateTimeAtStartOfDay()); setStrName(itemname.getText());//from www . ja v a 2 s . c om ok = true; setVisible(false); }
From source file:mbsystem.controller.BookListController.java
/** * Get a list of latest books/*from www .jav a2 s . co m*/ * * @return latest books */ public List<Book> getLatestBooks() { List<Book> latestBooks = new ArrayList<>(); try { DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Date today = new Date(); LocalDate localToday = LocalDate.fromDateFields(today); for (Book b : allBooks) { // the publishDate is stored as String in database String pubDateString = b.getPublishDate(); // parse the string Date pubDate = df.parse(pubDateString); LocalDate localPubDate = LocalDate.fromDateFields(pubDate); // calculate the days since book published int publishedDays = Days.daysBetween(localPubDate, localToday).getDays(); // if published within one year if (publishedDays < 365) { latestBooks.add(b); } } } catch (ParseException e) { System.out.println("Invalid date format."); } return latestBooks; }
From source file:net.diogobohm.timed.api.ui.domain.builder.OverviewBuilder.java
public Overview build(Date startDate, Date endDate, List<Task> tasks) { Date safeEndDate = getSafeEndDate(endDate); List<DayTaskList> dayTasks = Lists.newArrayList(); Multimap<LocalDate, Task> dayTaskMap = createDayTaskMap(tasks); LocalDate startDay = LocalDate.fromDateFields(startDate); LocalDate endDay = LocalDate.fromDateFields(safeEndDate); for (LocalDate curDay = startDay; !curDay.isAfter(endDay); curDay = curDay.plusDays(1)) { List<Task> curDayTasks = Lists.newArrayList(); if (dayTaskMap.containsKey(curDay)) { curDayTasks.addAll(dayTaskMap.get(curDay)); }/*w w w . j av a2 s . c om*/ dayTasks.add(new DayTaskList(curDay.toDate(), new TaskList(curDayTasks))); } return new Overview(dayTasks); }
From source file:net.diogobohm.timed.api.ui.domain.builder.OverviewBuilder.java
private Multimap<LocalDate, Task> createDayTaskMap(List<Task> tasks) { Multimap<LocalDate, Task> dayTaskIndex = HashMultimap.create(); for (Task task : tasks) { LocalDate taskStart = LocalDate.fromDateFields(task.getStart()); dayTaskIndex.put(taskStart, task); }/* www.ja v a 2 s . c o m*/ return dayTaskIndex; }
From source file:nl.surfnet.coin.selfservice.control.StatisticsController.java
License:Apache License
private static LocalDate toLocalDate(long pointStart) { return LocalDate.fromDateFields(new Date(pointStart)); }