Search in sources :

Example 1 with MonthDay

use of org.joda.time.MonthDay in project joda-time-android by dlew.

the class TestDateUtils method testIsToday.

public void testIsToday() {
    LocalDate today = LocalDate.now();
    LocalDate yesterday = today.minusDays(1);
    LocalDate tomorrow = today.plusDays(1);
    assertEquals(true, DateUtils.isToday(today));
    assertEquals(false, DateUtils.isToday(yesterday));
    assertEquals(false, DateUtils.isToday(tomorrow));
    LocalDateTime todayLdt = LocalDateTime.now();
    LocalDateTime yesterdayLdt = todayLdt.minusDays(1);
    LocalDateTime tomorrowLdt = todayLdt.plusDays(1);
    assertEquals(true, DateUtils.isToday(todayLdt));
    assertEquals(false, DateUtils.isToday(yesterdayLdt));
    assertEquals(false, DateUtils.isToday(tomorrowLdt));
    DateTime todayDt = DateTime.now();
    DateTime yesterdayDt = todayDt.minusDays(1);
    DateTime tomorrowDt = todayDt.plusDays(1);
    assertEquals(true, DateUtils.isToday(todayDt));
    assertEquals(false, DateUtils.isToday(yesterdayDt));
    assertEquals(false, DateUtils.isToday(tomorrowDt));
    try {
        DateUtils.isToday(new MonthDay());
        fail("DateUtils.isToday() should have thrown an error since MonthDay has no year.");
    } catch (Exception e) {
    }
    try {
        DateUtils.isToday(new YearMonth());
        fail("DateUtils.isToday() should have thrown an error since YearMonth has no day.");
    } catch (Exception e) {
    }
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) YearMonth(org.joda.time.YearMonth) MonthDay(org.joda.time.MonthDay) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 2 with MonthDay

use of org.joda.time.MonthDay in project uPortal by Jasig.

the class EventDateTimeUtils method validateQuarters.

/**
 * Validates the collection of quarters is valid. Validity is defined as:
 *
 * <ul>
 *   <li>Contains 4 QuarterDetail
 *   <li>Once placed in order the start of the current quarter is equal to the end of the
 *       previous quarter
 *   <li>Once placed in order the quarterId values go from 0 to 3 in order
 * </ul>
 *
 * @param quarters
 * @return A new list of the quarters sorted by natural id
 */
public static List<QuarterDetail> validateQuarters(Collection<QuarterDetail> quarters) {
    if (quarters.size() != 4) {
        throw new IllegalArgumentException("Exactly 4 QuarterDetail must be set: " + quarters);
    }
    final List<QuarterDetail> sortedQuarters = new ArrayList<QuarterDetail>(quarters);
    Collections.sort(sortedQuarters);
    MonthDay previousEnd = sortedQuarters.get(3).getEnd();
    final Iterator<QuarterDetail> itr = sortedQuarters.iterator();
    for (int i = 0; i < 4; i++) {
        final QuarterDetail q = itr.next();
        if (i != q.getQuarterId()) {
            throw new IllegalArgumentException("Quarter " + i + " has an illegal id of " + q.getQuarterId());
        }
        if (!q.getStart().equals(previousEnd)) {
            throw new IllegalArgumentException("Quarter " + i + " start date of " + q.getStart() + " is not adjacent to previous quarter's end date of " + previousEnd);
        }
        previousEnd = q.getEnd();
    }
    return sortedQuarters;
}
Also used : ArrayList(java.util.ArrayList) MonthDay(org.joda.time.MonthDay)

Aggregations

MonthDay (org.joda.time.MonthDay)2 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalDateTime (org.joda.time.LocalDateTime)1 YearMonth (org.joda.time.YearMonth)1