-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2fcs
-
sparc
-
solaris_2.5
-
Verified
Name: dfC67450 Date: 08/17/98
java.util.GregorianCalendar.getActualMaximum(YEAR) always returns 292278994.
This is the reason of wrong work of other methods like computeTime().
The source code contains the comments
* (!) The real maxima for YEAR depend on the type of calendar:
*
* Gregorian = May 17, 292275056 BC - Aug 17, 292278994 AD
* Julian = Dec 2, 292269055 BC - Jan 3, 292272993 AD
* Hybrid = Dec 2, 292269055 BC - Aug 17, 292278994 AD
*
* Most calendars, including default calendar objects, will be
* hybrids. For the purposes of the LEAST_MAX_VALUES and
* MAX_VALUES, we just use the outer limit 292278994 for now.
* Computing a real maximum (as in getActualMaximum()) will
* involve taking the other fields and the cutover into
* account, an overly complex calculation for such an unlikely
* date. Liu 6/5/98.
It means that actual maximum of YEAR should depend on ERA, DATE and MONTH fields.
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.util.*;
public class Test {
public static void main (String args[]){
boolean passed = true;
int field = Calendar.YEAR;
GregorianCalendar calendar = new GregorianCalendar(1998, 10, 1);
Date dateBefore = calendar.getTime();
int maxYear = calendar.getActualMaximum(field);
int years[] = {2000, maxYear-1, maxYear};
System.out.println("maxYear: " + maxYear);
for (int i = 0; i < years.length; i++) {
calendar.set(field, years[i]);
Date dateAfter = calendar.getTime(); // compute time and field
int newYear = calendar.get(field);
if (newYear != years[i]) {
System.out.println(" Test failed with year = " + years[i]);
System.out.println(" date before: " + dateBefore);
System.out.println(" date after: " + dateAfter);
System.out.println(" newYear should be equal the year, date, month and time shouldn't change");
} else System.out.println(" Test passed with year = " + years[i]);
}
}
}
---------Output from the test---------------------
maxYear: 292278994
Test passed with year = 2000
Test passed with year = 292278993
Test failed with year = 292278994
date before: Sun Nov 01 00:00:00 GMT+03:00 1998
date after: Thu Sep 28 08:34:08 GMT+03:00 292263053
newYear should be equal the year, date, month and time shouldn't change
-------------------------------------------------
======================================================================