Example usage for org.joda.time Years yearsBetween

List of usage examples for org.joda.time Years yearsBetween

Introduction

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

Prototype

public static Years yearsBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Years representing the number of whole years between the two specified partial datetimes.

Usage

From source file:py.com.palermo.curriculolanacion.entities.Curriculo.java

public Integer getEdad() {
    if (anioNac != null && mesNac != null && diaNac != null) {
        LocalDate birthdate = LocalDate.parse(anioNac + "-" + mesNac + "-" + diaNac,
                DateTimeFormat.forPattern("yyyy-MM-dd"));

        LocalDate now = new LocalDate();
        Years age = Years.yearsBetween(birthdate, now);
        edad = age.getYears();/*from  w ww  . j a  v  a 2s.co m*/
    }
    return edad;
}

From source file:routines.BRules.java

License:Apache License

/**
 * For internal use only/*from   www.  j a  v a 2s . c  o m*/
 * 
 * Joda Time classes aren't exposed to the calling Talend jobs because of
 * library dependency management
 * 
  * @param birthDate date of birth
  * @param asOfDate date of comparison (instead of today)
  * @return whole years of age
 */
static Integer ageInYears(LocalDate birthDate, LocalDate asOfDate) {

    if (birthDate == null || asOfDate == null) {
        return null;
    }

    Years age = Years.yearsBetween(birthDate, asOfDate);

    return age.getYears();
}

From source file:uk.org.rbc1b.roms.controller.volunteer.VolunteerBadgePdfModelFactory.java

License:Open Source License

/**
 * Determines the colour of the badge depending on the volunteer details
 * such as their age and departmental assignment.
 *
 * @param volunteer volunteer//from www  .ja  v  a  2s . co  m
 * @return VolunteerBadgeColour the colour
 */
public VolunteerBadgeColour determineBadgeColour(Volunteer volunteer) {
    LocalDate birthDate = LocalDate.fromDateFields(volunteer.getPerson().getBirthDate());
    LocalDate now = new LocalDate();
    Years age = Years.yearsBetween(birthDate, now);

    // volunteer badge colour depends on age or assignment
    if (age.getYears() >= 13 && age.getYears() <= 15) {
        return VolunteerBadgeColour.GREEN;
    } else if (age.getYears() >= 16 && age.getYears() <= 17) {
        return VolunteerBadgeColour.ORANGE;
    } else if (isVolunteerAssignmentDangerous(volunteer)) {
        return VolunteerBadgeColour.RED;
    } else {
        return VolunteerBadgeColour.GREY;
    }
}

From source file:utility.DateUtil.java

License:Apache License

/**
 * Get the age/*from  w  w w  . j  a v a 2 s .  c o m*/
 *
 * @param yyyy
 * @param mm
 * @param dd
 * @return age in String
 */
public static String getAge(final int yyyy, final int mm, final int dd) {

    LocalDate birthdate = new LocalDate(yyyy, mm, dd);
    LocalDate now = new LocalDate();
    Years age = Years.yearsBetween(birthdate, now);
    final String mAge = age.getYears() + "";
    return mAge;
}

From source file:za.co.bayport.rules.PolicyRules.java

/**
 * Checks Applicant's Age Limit<br/>
 * <br/>/*from  w  ww .j  ava2s .c o  m*/
 * 
 * @param minVal
 *            : Applicant's Minimum Age
 * @param maxVal
 *            : Applicant's Maximum Age
 * @param val
 *            : Applicant's age
 * @throws ServiceException
 *             : Would throw ServiceException containing &lt;errorCode&gt;, &lt;fieldName&gt; and &lt;fieldValue&gt; if: <li>
 *             &lt;minVal&gt; is zero or null</li><li>&lt;maxVal&gt; is zero or null</li> <li>&lt;val&gt; is zero or null</li> <li>if &lt;val&gt; is less
 *             than &lt;minVal&gt; or greater than &lt;maxVal&gt;<br/>
 *             <br/>
 *             <b>Suggestion:</b> Applicant must be 18 years of age or older but not older than 63 years of age. Unless: The employer can provide
 *             confirmation in writing that the applicant will be employed after reaching 63 to a maximum of 65 years of age
 */
public static ServiceException checkAgeLimit(Integer minVal, Integer maxVal, Date dob) {

    ServiceException ServiceException = checkIsNullOrZero("RUL002", "AGE", "Minimum Age: Is Null Or Zero",
            minVal);
    if (ServiceException == null)
        ServiceException = checkIsNullOrZero("RUL002", "AGE", "Maximum Age: Is Null Or Zero", maxVal);

    if (ServiceException == null)
        ServiceException = checkIsNullOrEmpty("RUL001", "AGE", "Date of Birth Is Null or Empty", dob);

    if (ServiceException == null) {
        DateMidnight birthdate = new DateMidnight(dob);
        DateTime now = new DateTime();
        Years age = Years.yearsBetween(birthdate, now);
        int val = age.getYears();
        if (val < minVal || val > maxVal)
            ServiceException = new ServiceException("POL002", "AGE",
                    "Applicant must be 18 years of age or older but not older than 63 years of age. Unless: The employer can provide confirmation in writing that the applicant will be employed after reaching 63 to a maximum of 65 years of age");
    }
    return ServiceException;
}