List of usage examples for org.joda.time Years getYears
public int getYears()
From source file:ar.edu.utn.frre.dacs.sample.model.Cliente.java
License:Apache License
/** * Retorna la edad del cliente en base a la fecha de nacimiento y la * fecha actual.//from ww w . j av a 2 s. c om * @return Edad del Cliente. */ public int getEdad() { if (fechaNacimiento == null) return 0; LocalDate birthdate = new LocalDate(fechaNacimiento.getTime()); LocalDate now = new LocalDate(); Years age = Years.yearsBetween(birthdate, now); return age.getYears(); }
From source file:be.fedict.eid.idp.attribute.age.AgeAttributeService.java
License:Open Source License
public void addAttribute(Map<String, Attribute> attributeMap) { Attribute dobAttribute = attributeMap.get(DefaultAttribute.DATE_OF_BIRTH.getUri()); if (null == dobAttribute) { return;//from w ww . ja va 2s.c om } LOG.debug("Add age attribute"); GregorianCalendar dobValue = (GregorianCalendar) dobAttribute.getValue(); DateTime dob = new DateTime(dobValue.getTime()); DateTime now = new DateTime(); Years years = Years.yearsBetween(dob, now); int age = years.getYears(); attributeMap.put(URI, new Attribute(URI, AttributeType.INTEGER, age)); }
From source file:c4a.platform.services.wsServices.java
@GET @Path("getCareReceivers") @Consumes("application/json") @Produces("application/json") public C4ACareReceiversResponse getJson() throws IOException { /**/*www.ja va 2 s . co m*/ * ****************Variables************* */ System.out.println("******************start*****************"); C4ACareReceiversResponse response = new C4ACareReceiversResponse(); TypedQuery query; TypedQuery query_crProfile; TypedQuery query_users; TypedQuery query_frailty; List<UserInRole> userinroleparamsList; List<CrProfile> crprofileparamsList; List<CareProfile> careprofileparamsList; List<FrailtyStatusTimeline> frailtyparamsList; ArrayList<C4ACareReceiverListResponse> itemList; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); /** * ****************Action************* */ // if (em == null) { // init(); // } query_users = (TypedQuery) em.createQuery("SELECT u FROM UserInRole u Where u.roleId.id =1"); userinroleparamsList = query_users.getResultList(); if (userinroleparamsList.isEmpty()) { response.setMessage("No users found"); response.setResponseCode(0); return response; } else { itemList = new ArrayList<C4ACareReceiverListResponse>(); for (UserInRole users : userinroleparamsList) { response.setMessage("success"); response.setResponseCode(10); System.out.println("id " + users.getId() + "name " + users.getUserInSystemId().getUsername()); query_crProfile = (TypedQuery) em .createQuery("SELECT c FROM CrProfile c Where c.userInRoleId.id = :userId "); query_crProfile.setParameter("userId", users.getId()); //we use list to avoid "not found" exception crprofileparamsList = query_crProfile.getResultList(); int age = 0; if (!crprofileparamsList.isEmpty()) { LocalDate birthDate = new LocalDate(crprofileparamsList.get(0).getBirthDate()); Years age2 = Years.yearsBetween(birthDate, new LocalDate()); age = age2.getYears(); // System.out.println("age2 " + age2.getYears()); // System.out.println("user name " + crprofileparamsList.get(0).getUserInRoleId().getId() // + " birthDate " + birthDate); } query = (TypedQuery) em.createQuery("SELECT c FROM CareProfile c WHERE c.userInRole.id = :userId "); query.setParameter("userId", users.getId()); //we use list to avoid "not found" exception careprofileparamsList = query.getResultList(); //************************************** String frailtyStatus = null; String frailtyNotice = null; char attention = 0; String textline = null; char interventionstatus = 0; String interventionDate = null; String detectionStatus = null; String detectionDate = null; if (!careprofileparamsList.isEmpty()) { // frailtyStatus = careprofileparamsList.get(0).getFrailtyStatus(); // frailtyNotice = careprofileparamsList.get(0).getFrailtyNotice(); attention = careprofileparamsList.get(0).getAttentionStatus(); textline = careprofileparamsList.get(0).getIndividualSummary(); interventionstatus = careprofileparamsList.get(0).getInterventionStatus(); interventionDate = sdf.format(careprofileparamsList.get(0).getLastInterventionDate()); // detectionStatus = careprofileparamsList.get(0).getDetectionStatus(); // detectionDate = sdf.format(new Date(careprofileparamsList.get(0).getLastDetection() * 1000)); // System.out.println("user id " + careprofileparamsList.get(0).getUserInRoleId() // + " frailty status " + careprofileparamsList.get(0).getFrailtyStatus()); } query_frailty = (TypedQuery) em.createQuery( "SELECT f FROM FrailtyStatusTimeline f WHERE f.frailtyStatusTimelinePK.userInRoleId = :userId "); query_frailty.setParameter("userId", users.getId()); //we use list to avoid "not found" exception frailtyparamsList = query_frailty.getResultList(); if (!frailtyparamsList.isEmpty()) { frailtyStatus = frailtyparamsList.get(0).getFrailtyStatus().getFrailtyStatus(); frailtyNotice = frailtyparamsList.get(0).getFrailtyNotice(); // System.out.println("user id " + frailtyparamsList.get(0).getFrailtyStatusTimelinePK().getUserInRoleId() // + " frailty status " + frailtyparamsList.get(0).getFrailtyStatus().getFrailtyStatus()); } itemList.add(new C4ACareReceiverListResponse(users.getId(), age, frailtyStatus, frailtyNotice, attention, textline, interventionstatus, interventionDate, detectionStatus, detectionDate)); } //detectionVariables loop response.setItemList(itemList); } //end detectionVariables is empty return response; }
From source file:ch.thn.gedcom.GedcomHelper.java
License:Apache License
/** * Calculates the age of the person between the given birthDate and the toDate * /* w ww. j a va 2 s. c om*/ * @param fromDate * @param toDate * @return */ public static int getAge(Date fromDate, Date toDate) { if (fromDate == null || toDate == null) { return 0; } DateMidnight bd = new DateMidnight(fromDate); DateTime now = new DateTime(toDate); Years age = Years.yearsBetween(bd, now); return age.getYears(); }
From source file:com.boha.golfkids.util.NewGolfGroupUtil.java
private static int getPlayerAge(long date) { LocalDateTime birthday = new LocalDateTime(date); LocalDateTime start = new LocalDateTime(); Years years = Years.yearsBetween(birthday, start); return years.getYears(); }
From source file:com.cisco.dvbu.ps.utils.date.DateDiffDate.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. */// w w w . j a v a 2 s.co m public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { java.util.Date startDate = null; java.util.Date endDate = null; Calendar startCal = null; Calendar endCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; long dateLength = 0; try { result = null; if (inputValues[0] == null) { result = new Long(dateLength); return; } if (inputValues[1] == null) { result = new Long(dateLength); return; } if (inputValues[2] == null) { result = new Long(dateLength); return; } datePart = (String) inputValues[0]; startDate = (java.util.Date) inputValues[1]; startCal = Calendar.getInstance(); startCal.setTime(startDate); endDate = (java.util.Date) inputValues[2]; endCal = Calendar.getInstance(); endCal.setTime(endDate); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1, endCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); if (datePart.equalsIgnoreCase("second")) { Seconds seconds = Seconds.secondsBetween(startDateTime, endDateTime); dateLength = seconds.getSeconds(); } if (datePart.equalsIgnoreCase("minute")) { Minutes minutes = Minutes.minutesBetween(startDateTime, endDateTime); dateLength = minutes.getMinutes(); } if (datePart.equalsIgnoreCase("hour")) { Hours hours = Hours.hoursBetween(startDateTime, endDateTime); dateLength = hours.getHours(); } if (datePart.equalsIgnoreCase("day")) { Days days = Days.daysBetween(startDateTime, endDateTime); dateLength = days.getDays(); } if (datePart.equalsIgnoreCase("week")) { Weeks weeks = Weeks.weeksBetween(startDateTime, endDateTime); dateLength = weeks.getWeeks(); } if (datePart.equalsIgnoreCase("month")) { Months months = Months.monthsBetween(startDateTime, endDateTime); dateLength = months.getMonths(); } if (datePart.equalsIgnoreCase("year")) { Years years = Years.yearsBetween(startDateTime, endDateTime); dateLength = years.getYears(); } result = new Long(dateLength); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.cisco.dvbu.ps.utils.date.DateDiffTimestamp.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. *///from w ww . java2s . co m public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { Timestamp startTimestamp = null; Timestamp endTimestamp = null; Calendar startCal = null; Calendar endCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; long dateLength = 0; try { result = null; if (inputValues[0] == null) { result = new Long(dateLength); return; } if (inputValues[1] == null) { result = new Long(dateLength); return; } if (inputValues[2] == null) { result = new Long(dateLength); return; } datePart = (String) inputValues[0]; startTimestamp = (Timestamp) inputValues[1]; // long startMilliseconds = startTimestamp.getTime() + // (startTimestamp.getNanos() / 1000000); long startMilliseconds = startTimestamp.getTime() + (startTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0); startCal = Calendar.getInstance(); startCal.setTimeInMillis(startMilliseconds); endTimestamp = (Timestamp) inputValues[2]; // long endMilliseconds = endTimestamp.getTime() + // (endTimestamp.getNanos() / 1000000); long endMilliseconds = endTimestamp.getTime() + (endTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0); endCal = Calendar.getInstance(); endCal.setTimeInMillis(endMilliseconds); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY), startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND), startCal.get(Calendar.MILLISECOND)); endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1, endCal.get(Calendar.DAY_OF_MONTH), endCal.get(Calendar.HOUR_OF_DAY), endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), endCal.get(Calendar.MILLISECOND)); Interval interval = new Interval(startDateTime, endDateTime); if (datePart.equalsIgnoreCase("second") || datePart.equalsIgnoreCase("ss")) { Seconds seconds = Seconds.secondsIn(interval); dateLength = seconds.getSeconds(); } else if (datePart.equalsIgnoreCase("minute") || datePart.equalsIgnoreCase("mi")) { Minutes minutes = Minutes.minutesIn(interval); dateLength = minutes.getMinutes(); } else if (datePart.equalsIgnoreCase("hour") || datePart.equalsIgnoreCase("hh")) { Hours hours = Hours.hoursIn(interval); dateLength = hours.getHours(); } else if (datePart.equalsIgnoreCase("day") || datePart.equalsIgnoreCase("dd")) { Days days = Days.daysIn(interval); dateLength = days.getDays(); } else if (datePart.equalsIgnoreCase("week") || datePart.equalsIgnoreCase("wk")) { Weeks weeks = Weeks.weeksIn(interval); dateLength = weeks.getWeeks(); } else if (datePart.equalsIgnoreCase("month") || datePart.equalsIgnoreCase("mm")) { Months months = Months.monthsIn(interval); dateLength = months.getMonths(); } else if (datePart.equalsIgnoreCase("year") || datePart.equalsIgnoreCase("yy")) { Years years = Years.yearsIn(interval); dateLength = years.getYears(); } else if (datePart.equalsIgnoreCase("millisecond") || datePart.equalsIgnoreCase("ms")) { dateLength = (endTimestamp.getTime() - startTimestamp.getTime()); // millis } else if (datePart.equalsIgnoreCase("microsecond") || datePart.equalsIgnoreCase("mcs")) { dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds * 1000000L // micros + (endTimestamp.getNanos() - startTimestamp.getNanos()) / 1000; // nanos/1000 } else if (datePart.equalsIgnoreCase("nanosecond") || datePart.equalsIgnoreCase("ns")) { dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds * 1000000000L // nanos + (endTimestamp.getNanos() - startTimestamp.getNanos()); // nanos } else { throw new IllegalArgumentException(datePart); } result = new Long(dateLength); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.fct.api.utils.IdcardUtils.java
License:Open Source License
public static int getAgeByBirthday(Date birthday) { LocalDate birthdayDate = new LocalDate(birthday); LocalDate now = new LocalDate(); Years age = Years.yearsBetween(birthdayDate, now); return age.getYears(); }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * get total times (Age) based on date parameter * * @param birthDate input date type// ww w.jav a 2 s . c o m * @return Integer age that calculate from today * @throws java.lang.Exception * */ public static Integer getAge(Date birthDate) throws Exception { if (birthDate.after(new Date())) { throw new Exception("Mr DHFR say :Your birthdate is newer than to day. Can't be born in the future!"); } else { DateMidnight date1 = new DateMidnight(birthDate); DateTime now = new DateTime(); Years years = Years.yearsBetween(date1, now); return years.getYears(); } }
From source file:com.inkubator.hrm.web.payroll.SalaryConfirmationDetailController.java
@PostConstruct @Override//from w ww .ja v a2s. c om public void initialization() { try { super.initialization(); ResourceBundle messages = ResourceBundle.getBundle("Messages", new Locale(FacesUtil.getSessionAttribute(HRMConstant.BAHASA_ACTIVE).toString())); String empDataId = FacesUtil.getRequestParameter("execution"); selectedPayTempKalkulasi = payTempKalkulasiService .getEntityByEmpIdAndModelTakeHomePayId(Long.parseLong(empDataId.substring(1))); WtPeriode wtPeriode = wtPeriodeService.getEntityByPayrollTypeActive(); DateMidnight date1 = new DateMidnight(selectedPayTempKalkulasi.getEmpData().getJoinDate()); DateTime now = new DateTime(wtPeriode.getUntilPeriode()); // mencari total tahun Years years = Years.yearsBetween(date1, now); //mencari total bulan Integer totalMonth = DateTimeUtil.getTotalMonthDifference( selectedPayTempKalkulasi.getEmpData().getJoinDate(), wtPeriode.getUntilPeriode()); //mencari total sisa bulan Integer totalMonthDifference = totalMonth - (12 * years.getYears()); yearMonth = years.getYears() + " " + messages.getString("global.year") + " " + totalMonthDifference + " " + messages.getString("global.month"); //list pay temp kalkulasi listPayTempKalkulasi = payTempKalkulasiService .getAllDataByEmpDataIdAndExcludeCompTHP(Long.valueOf(empDataId.substring(1))); listTempKalkulasiPajak = payTempKalkulasiEmpPajakService .getAllDataByEmpDataId(Long.valueOf(empDataId.substring(1))); listPayReceiverAccountModel = payReceiverBankAccountService .getAllDataByEmpDataId(Long.valueOf(empDataId.substring(1))); } catch (Exception ex) { LOGGER.error("Error", ex); } }