Example usage for org.joda.time Months getMonths

List of usage examples for org.joda.time Months getMonths

Introduction

In this page you can find the example usage for org.joda.time Months getMonths.

Prototype

public int getMonths() 

Source Link

Document

Gets the number of months that this period represents.

Usage

From source file:femr.util.calculations.dateUtils.java

License:Open Source License

public static float getAgeAsOfDateFloat(Date born, DateTime asOfDate) {

    LocalDate birthdate = new LocalDate(born);
    LocalDate currDate = new LocalDate(asOfDate);
    Months months = Months.monthsBetween(birthdate, currDate);
    int monthsInt = months.getMonths();
    float result = (float) monthsInt;
    return result / 12;
}

From source file:influent.server.utilities.DateRangeBuilder.java

License:MIT License

public static FL_DateRange getDateRange(DateTime startDate, DateTime endDate) {

    if (startDate == null || endDate == null) {
        return null;
    }/*from w  w  w. jav  a  2s  . co m*/

    // TODO: add support for numIntervalsPerBin, but on the client resource side in charts only.
    Days days = Days.daysBetween(startDate, endDate);
    if (days.getDays() == 14) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 14L);
    }
    //      if (days.getDays() == 30) { return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 15L, 2); }
    //      if (days.getDays() == 60) { return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 15L, 4); }
    Weeks weeks = Weeks.weeksBetween(startDate, endDate);
    if (weeks.getWeeks() == 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 16L);
    }
    //      if (weeks.getWeeks() == 32) { return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 16L, 2); }
    Months months = Months.monthsBetween(startDate, endDate);
    if (months.getMonths() == 12) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 12L);
    }
    if (months.getMonths() == 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 16L);
    }
    //      if (months.getMonths() == 24) { return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 16L, 2); }
    if (months.getMonths() == 32) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 12L);
    }
    Years years = Years.yearsBetween(startDate, endDate);
    if (years.getYears() == 4) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 16L);
    }
    //      if (years.getYears() == 8) { return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 16L, 2); }
    if (years.getYears() == 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.YEARS, 16L);
    }

    throw new RuntimeException("Unsupported chart date range: " + startDate + " to " + endDate);
}

From source file:influent.server.utilities.DateRangeBuilder.java

License:MIT License

public static FL_DateRange getBigChartDateRange(DateTime startDate, DateTime endDate) {
    if (startDate == null || endDate == null) {
        return null;
    }//from  www  .j  av a2 s . c  o m

    Days days = Days.daysBetween(startDate, endDate);
    if (days.getDays() <= 14) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 14L);
    }
    if (days.getDays() <= 30) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 30L);
    }
    if (days.getDays() <= 60) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 60L);
    }
    Weeks weeks = Weeks.weeksBetween(startDate, endDate);
    if (weeks.getWeeks() <= 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 112L);
    }
    if (weeks.getWeeks() <= 32) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 32L);
    }
    Months months = Months.monthsBetween(startDate, endDate);
    if (months.getMonths() <= 12) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 52);
    }
    if (months.getMonths() <= 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 70L);
    }
    if (months.getMonths() <= 24) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 24L);
    }
    if (months.getMonths() <= 32) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 32L);
    }
    Years years = Years.yearsBetween(startDate, endDate);
    if (years.getYears() <= 4) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 48L);
    }
    if (years.getYears() <= 5) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 60L);
    }
    if (years.getYears() <= 6) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 72L);
    }
    if (years.getYears() <= 7) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 84L);
    }
    if (years.getYears() <= 8) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 96L);
    }
    if (years.getYears() <= 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 64L);
    }

    throw new RuntimeException("Unsupported chart date range: " + startDate + " to " + endDate);
}

From source file:influent.server.utilities.DateRangeBuilder.java

License:MIT License

public static int determineInterval(DateTime date, DateTime startDate, FL_DateInterval interval,
        int numIntervalsPerBin) {
    switch (interval) {
    case SECONDS:
        Seconds seconds = Seconds.secondsBetween(startDate, date);
        return seconds.getSeconds() / numIntervalsPerBin;
    case HOURS://w ww .j  a  v  a2s  .c o m
        Hours hours = Hours.hoursBetween(startDate, date);
        return hours.getHours() / numIntervalsPerBin;
    case DAYS:
        Days days = Days.daysBetween(startDate, date);
        return days.getDays() / numIntervalsPerBin;
    case WEEKS:
        Weeks weeks = Weeks.weeksBetween(startDate, date);
        return weeks.getWeeks() / numIntervalsPerBin;
    case MONTHS:
        Months months = Months.monthsBetween(startDate, date);
        return months.getMonths() / numIntervalsPerBin;
    case QUARTERS:
        months = Months.monthsBetween(startDate, date);
        return months.getMonths() / 3 / numIntervalsPerBin;
    case YEARS:
        Years years = Years.yearsBetween(startDate, date);
        return years.getYears() / numIntervalsPerBin;
    }
    return 0;
}

From source file:it.webappcommon.lib.DateUtils.java

License:Open Source License

public static int differenzaInMesi(Date start, Date end) {
    int res = 0;/*from   w  ww  .j  a  v  a2s  .  c  o m*/

    DateTime startDate = new DateTime(start);
    DateTime endDate = new DateTime(end);

    Months mesi = Months.monthsBetween(startDate, endDate);
    res = mesi.getMonths();

    return res;
}

From source file:net.sourceforge.fenixedu.domain.Person.java

License:Open Source License

public boolean areContactsRecent(final Class<? extends PartyContact> contactClass, final int daysNotUpdated) {
    final List<? extends PartyContact> partyContacts = getPartyContacts(contactClass);
    boolean isUpdated = false;
    for (final PartyContact partyContact : partyContacts) {
        if (partyContact.getLastModifiedDate() == null) {
            isUpdated = isUpdated || false;
        } else {//  www.  j  av  a2  s.  c  o  m
            final DateTime lastModifiedDate = partyContact.getLastModifiedDate();
            final DateTime now = new DateTime();
            final Months months = Months.monthsBetween(lastModifiedDate, now);
            if (months.getMonths() > daysNotUpdated) {
                isUpdated = isUpdated || false;
            } else {
                isUpdated = isUpdated || true;
            }
        }
    }
    return isUpdated;
}

From source file:net.technicpack.launcher.ui.components.news.AuthorshipWidget.java

License:Open Source License

private String getDateText(Date date) {
    LocalDate posted = new LocalDate(date.getTime());
    LocalDate now = new LocalDate();

    Years yearsSince = Years.yearsBetween(posted, now);
    Months monthsSince = Months.monthsBetween(posted, now);
    Days daysSince = Days.daysBetween(posted, now);
    Hours hoursSince = Hours.hoursBetween(posted, now);
    Minutes minutesSince = Minutes.minutesBetween(posted, now);

    if (yearsSince.getYears() > 1)
        return resources.getString("time.years", Integer.toString(yearsSince.getYears()));
    else if (yearsSince.getYears() == 1)
        return resources.getString("time.year");
    else if (monthsSince.getMonths() > 1)
        return resources.getString("time.months", Integer.toString(monthsSince.getMonths()));
    else if (monthsSince.getMonths() == 1)
        return resources.getString("time.month");
    else if (daysSince.getDays() > 1)
        return resources.getString("time.days", Integer.toString(daysSince.getDays()));
    else if (daysSince.getDays() == 1)
        return resources.getString("time.day");
    else if (hoursSince.getHours() > 1)
        return resources.getString("time.hours", Integer.toString(hoursSince.getHours()));
    else if (hoursSince.getHours() == 1)
        return resources.getString("time.hour");
    else if (minutesSince.getMinutes() > 1)
        return resources.getString("time.minutes", Integer.toString(minutesSince.getMinutes()));
    else// w ww. j  a va 2 s .c  o  m
        return resources.getString("time.minute");
}

From source file:org.apache.pig.builtin.MonthsBetween.java

License:Apache License

@Override
public Long exec(Tuple input) throws IOException {
    if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
        return null;
    }/*from w  ww  .  jav  a 2 s. c om*/

    DateTime startDate = (DateTime) input.get(0);
    DateTime endDate = (DateTime) input.get(1);

    // Larger value first
    Months m = Months.monthsBetween(endDate, startDate);
    // joda limitation, only integer range, at the risk of overflow, need to be improved
    return (long) m.getMonths();

}

From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISOMonthsBetween.java

License:Apache License

@Override
public Long exec(Tuple input) throws IOException {
    if (input == null || input.size() < 2) {
        return null;
    }//from  ww w . j  a  va 2 s  .c om

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    DateTime startDate = new DateTime(input.get(0).toString());
    DateTime endDate = new DateTime(input.get(1).toString());

    // Larger value first
    Months m = Months.monthsBetween(endDate, startDate);
    long months = m.getMonths();

    return months;

}

From source file:org.encuestame.utils.DateUtil.java

License:Apache License

/**
 * Get Months Between Dates.//from w w w  . jav a2s  .  c o m
 * @param startDate
 * @return
 */
public static Integer getMothsBetweenDates(final Date startDate) {
    final DateTime currentDate = new DateTime();
    final DateTime storedDate = new DateTime(startDate);
    final Months monthsBetween = Months.monthsBetween(storedDate, currentDate);
    return monthsBetween.getMonths();
}