public void testMaxYear() {
final ISOChronology chrono = ISOChronology.getInstanceUTC();
final int maxYear = chrono.year().getMaximumValue();
DateTime start = new DateTime(maxYear, 1, 1, 0, 0, 0, 0, chrono);
DateTime end = new DateTime(maxYear, 12, 31, 23, 59, 59, 999, chrono);
assertTrue(start.getMillis() > 0);
assertTrue(end.getMillis() > start.getMillis());
assertEquals(maxYear, start.getYear());
assertEquals(maxYear, end.getYear());
long delta = end.getMillis() - start.getMillis();
long expectedDelta =
(start.year().isLeap() ? 366L : 365L) * DateTimeConstants.MILLIS_PER_DAY - 1;
assertEquals(expectedDelta, delta);
assertEquals(start, new DateTime(maxYear + "-01-01T00:00:00.000Z", chrono));
assertEquals(end, new DateTime(maxYear + "-12-31T23:59:59.999Z", chrono));
try {
start.plusYears(1);
fail();
} catch (IllegalFieldValueException e) {
}
try {
end.plusYears(1);
fail();
} catch (IllegalFieldValueException e) {
}
assertEquals(maxYear + 1, chrono.year().get(Long.MAX_VALUE));