Java Code Examples for org.joda.time.Months#getMonths()
The following examples show how to use
org.joda.time.Months#getMonths() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MonthsBetween.java From spork with Apache License 2.0 | 6 votes |
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) { return null; } 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(); }
Example 2
Source File: ISOMonthsBetween.java From spork with Apache License 2.0 | 6 votes |
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; } if (input.get(0) == null || input.get(1) == null) { return null; } 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; }
Example 3
Source File: Person.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
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 { 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; }
Example 4
Source File: InvoiceAttributesVM.java From estatio with Apache License 2.0 | 6 votes |
private String getFrequencyElseNull() { final SortedSet<InvoiceItem> items = invoice.getItems(); if(items.isEmpty()) { return null; } final InvoiceItem item = items.first(); final LocalDate startDate = item.getStartDate(); final LocalDate endDate = item.getEndDate(); if(startDate == null || endDate == null) { return null; } Months months = Months.monthsBetween(startDate, endDate.plusDays(1)); switch (months.getMonths()) { case 12: return "YEAR"; case 3: return "QUARTER"; case 1: return "MONTH"; } return null; }
Example 5
Source File: FrameworkUtils.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static int getDeltaSinceEpoch(int time, int tempRes) { int delta = 0; // Epoch MutableDateTime epoch = new MutableDateTime(); epoch.setDate(0); DateTime dt = new DateTime(time*1000, DateTimeZone.UTC); switch(tempRes) { case FrameworkUtils.HOUR: Hours hours = Hours.hoursBetween(epoch, dt); delta = hours.getHours(); break; case FrameworkUtils.DAY: Days days = Days.daysBetween(epoch, dt); delta = days.getDays(); break; case FrameworkUtils.WEEK: Weeks weeks = Weeks.weeksBetween(epoch, dt); delta = weeks.getWeeks(); break; case FrameworkUtils.MONTH: Months months = Months.monthsBetween(epoch, dt); delta = months.getMonths(); break; case FrameworkUtils.YEAR: Years years = Years.yearsBetween(epoch, dt); delta = years.getYears(); break; default: hours = Hours.hoursBetween(epoch, dt); delta = hours.getHours(); break; } return delta; }
Example 6
Source File: DateUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Calculates the number of months between the start and end-date. Note this * method is taking daylight saving time into account and has a performance * overhead. * * @param startDate the start date. * @param endDate the end date. * @return the number of months between the start and end date. */ public static int monthsBetween( Date startDate, Date endDate ) { final Months days = Months.monthsBetween( new DateTime( startDate ), new DateTime( endDate ) ); return days.getMonths(); }
Example 7
Source File: MonthsBetweenDates.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void months_between_two_dates_in_java_with_joda () { DateTime start = new DateTime(2005, 1, 1, 0, 0, 0, 0); DateTime end = new DateTime(2006, 1, 1, 0, 0, 0, 0); Months months = Months.monthsBetween(start, end); int monthsInYear = months.getMonths(); assertEquals(12, monthsInYear); }