/**
* Calendar.getActualMaximum(YEAR) works wrong.
*/
public void Test4167060() {
int field = Calendar.YEAR;
DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G",
Locale.US);
GregorianCalendar calendars[] = {
new GregorianCalendar(100, Calendar.NOVEMBER, 1),
new GregorianCalendar(-99 /* 100BC */, Calendar.JANUARY, 1),
new GregorianCalendar(1996, Calendar.FEBRUARY, 29),
};
String[] id = { "Hybrid", "Gregorian", "Julian" };
for (int k=0; k<3; ++k) {
logln("--- " + id[k] + " ---");
for (int j=0; j<calendars.length; ++j) {
GregorianCalendar calendar = calendars[j];
if (k == 1) {
calendar.setGregorianChange(new Date(Long.MIN_VALUE));
} else if (k == 2) {
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
}
format.setCalendar((Calendar)calendar.clone());
Date dateBefore = calendar.getTime();
int maxYear = calendar.getActualMaximum(field);
logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime()));
logln("date before: " + format.format(dateBefore));
int years[] = {2000, maxYear-1, maxYear, maxYear+1};
for (int i = 0; i < years.length; i++) {
boolean valid = years[i] <= maxYear;
calendar.set(field, years[i]);
Date dateAfter = calendar.getTime();
int newYear = calendar.get(field);
calendar.setTime(dateBefore); // restore calendar for next
// use
logln(" Year " + years[i] + (valid? " ok " : " bad") +
" => " + format.format(dateAfter));
if (valid && newYear != years[i]) {
errln(" FAIL: " + newYear + " should be valid; date, month and time shouldn't change");
} else if (!valid && newYear == years[i]) {
// We no longer require strict year maxima. That is, the
// calendar