Search in sources :

Example 1 with Years

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();
}
Also used : Years(org.joda.time.Years) Calendar(java.util.Calendar) LocalDate(org.joda.time.LocalDate)

Example 2 with Years

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 }));
    }
}
Also used : Years(org.joda.time.Years) DateMidnight(org.joda.time.DateMidnight) DateTime(org.joda.time.DateTime)

Example 3 with Years

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 "";
}
Also used : Years(org.joda.time.Years) LocalDate(org.joda.time.LocalDate)

Aggregations

Years (org.joda.time.Years)3 LocalDate (org.joda.time.LocalDate)2 Calendar (java.util.Calendar)1 DateMidnight (org.joda.time.DateMidnight)1 DateTime (org.joda.time.DateTime)1