// ----------------------------------------------------------------------- public void testGetters() { DateTime test = new DateTime(); assertEquals(ISO_DEFAULT, test.getChronology()); assertEquals(LONDON, test.getZone()); assertEquals(TEST_TIME_NOW, test.getMillis()); assertEquals(1, test.getEra()); assertEquals(20, test.getCenturyOfEra()); assertEquals(2, test.getYearOfCentury()); assertEquals(2002, test.getYearOfEra()); assertEquals(2002, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); assertEquals(2002, test.getWeekyear()); assertEquals(23, test.getWeekOfWeekyear()); assertEquals(7, test.getDayOfWeek()); assertEquals(160, test.getDayOfYear()); assertEquals(1, test.getHourOfDay()); assertEquals(0, test.getMinuteOfHour()); assertEquals(60, test.getMinuteOfDay()); assertEquals(0, test.getSecondOfMinute()); assertEquals(60 * 60, test.getSecondOfDay()); assertEquals(0, test.getMillisOfSecond()); assertEquals(60 * 60 * 1000, test.getMillisOfDay()); }
// ----------------------------------------------------------------------- private void check( DateTime test, int year, int month, int day, int hour, int min, int sec, int mil) { assertEquals(year, test.getYear()); assertEquals(month, test.getMonthOfYear()); assertEquals(day, test.getDayOfMonth()); assertEquals(hour, test.getHourOfDay()); assertEquals(min, test.getMinuteOfHour()); assertEquals(sec, test.getSecondOfMinute()); assertEquals(mil, test.getMillisOfSecond()); }
public void testMinYear() { final ISOChronology chrono = ISOChronology.getInstanceUTC(); final int minYear = chrono.year().getMinimumValue(); DateTime start = new DateTime(minYear, 1, 1, 0, 0, 0, 0, chrono); DateTime end = new DateTime(minYear, 12, 31, 23, 59, 59, 999, chrono); assertTrue(start.getMillis() < 0); assertTrue(end.getMillis() > start.getMillis()); assertEquals(minYear, start.getYear()); assertEquals(minYear, end.getYear()); long delta = end.getMillis() - start.getMillis(); long expectedDelta = (start.year().isLeap() ? 366L : 365L) * DateTimeConstants.MILLIS_PER_DAY - 1; assertEquals(expectedDelta, delta); String d = minYear + "-01-01T00:00:00.000"; Date date = dtf.parse(d); assertEquals(start, new DateTime(date, chrono)); String endStr = minYear + "-12-31T23:59:59.999"; date = dtf.parse(endStr); assertEquals(end, new DateTime(date, chrono)); try { start.minusYears(1); fail(); } catch (IllegalFieldValueException e) { } try { end.minusYears(1); fail(); } catch (IllegalFieldValueException e) { } assertEquals(minYear - 1, chrono.year().get(Long.MIN_VALUE)); }