use of org.joda.time.Years in project gradle by gradle.
the class Person method getAge.
public int getAge() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateOfBirth);
LocalDate birthdate = new LocalDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
LocalDate now = new LocalDate();
Years age = Years.yearsBetween(birthdate, now);
return age.getYears();
}
use of org.joda.time.Years in project head by mifos.
the class XlsClientsImporter method validateAge.
private void validateAge(final Date dateOfBirth) throws CellException, ConfigurationException {
final DateMidnight dob = new DateMidnight(dateOfBirth);
final DateTime now = new DateTime();
final Years age = Years.yearsBetween(dob, now);
final int minimumAge = ClientRules.getMinimumAge();
final int maximumAge = ClientRules.getMaximumAge();
if (age.getYears() < 0) {
throw new CellException(getMessage(XlsMessageConstants.FUTURE_DATE));
} else if (ClientRules.isAgeCheckEnabled() && !ClientRules.isAgeCheckWarningInsteadOfErrorEnabled() && (age.getYears() < minimumAge || age.getYears() > maximumAge)) {
throw new CellException(getMessage(XlsMessageConstants.INVALID_AGE, new Object[] { minimumAge, maximumAge }));
}
}
use of org.joda.time.Years in project head by mifos.
the class PersonnelBO method getAge.
public String getAge() {
if (this.personnelDetails != null && this.personnelDetails.getDob() != null && !this.personnelDetails.getDob().equals("")) {
LocalDate fromDate = new LocalDate(this.personnelDetails.getDob());
Years years = Years.yearsBetween(new LocalDate(), fromDate);
return Integer.valueOf(years.getYears()).toString();
}
return "";
}
Aggregations