-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: dfC67450 Date: 06/03/98
java.util.GregorianCalendar.setGregorianChange(Date cutover) sets the same year and era
when cutover is Date(Long.MIN_VALUE) and Date(Long.MAX_VALUE)
Javadoc says about setGregorianCalendar
To obtain a pure Julian calendar, set the change date to
Date(Long.MAX_VALUE). To obtain a pure Gregorian calendar,
set the change date to Date(Long.MIN_VALUE).
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.util.*;
public class Test {
public static void main (String args[]){
GregorianCalendar calendar = new GregorianCalendar();
calendar.setGregorianChange(new Date(Long.MIN_VALUE));
Date date1 = calendar.getGregorianChange();
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
Date date2 = calendar.getGregorianChange();
calendar.setTime(date1);
int year1 = calendar.get(Calendar.YEAR);
int era1 = calendar.get(Calendar.ERA);
calendar.setTime(date2);
int year2 = calendar.get(Calendar.YEAR);
int era2 = calendar.get(Calendar.ERA);
if (year1 == year2 && era1 == era2) {
System.out.println("test failed");
System.out.println("cutover date is Date(Long.MIN_VALUE)");
System.out.println(" cutover year: " + year1);
System.out.println(" cutover era: " + era1);
System.out.println("");
System.out.println("cutover date is Date(Long.MAX_VALUE)");
System.out.println(" cutover year: " + year2);
System.out.println(" cutover era: " + era2);
} else {
System.out.println("test passed");
}
}
}
---------Output from the test---------------------
test failed
cutover date is Date(Long.MIN_VALUE)
cutover year: 292269055
cutover era: 0
cutover date is Date(Long.MAX_VALUE)
cutover year: 292269055
cutover era: 0
-------------------------------------------------
======================================================================
java.util.GregorianCalendar.setGregorianChange(Date cutover) sets the same year and era
when cutover is Date(Long.MIN_VALUE) and Date(Long.MAX_VALUE)
Javadoc says about setGregorianCalendar
To obtain a pure Julian calendar, set the change date to
Date(Long.MAX_VALUE). To obtain a pure Gregorian calendar,
set the change date to Date(Long.MIN_VALUE).
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.util.*;
public class Test {
public static void main (String args[]){
GregorianCalendar calendar = new GregorianCalendar();
calendar.setGregorianChange(new Date(Long.MIN_VALUE));
Date date1 = calendar.getGregorianChange();
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
Date date2 = calendar.getGregorianChange();
calendar.setTime(date1);
int year1 = calendar.get(Calendar.YEAR);
int era1 = calendar.get(Calendar.ERA);
calendar.setTime(date2);
int year2 = calendar.get(Calendar.YEAR);
int era2 = calendar.get(Calendar.ERA);
if (year1 == year2 && era1 == era2) {
System.out.println("test failed");
System.out.println("cutover date is Date(Long.MIN_VALUE)");
System.out.println(" cutover year: " + year1);
System.out.println(" cutover era: " + era1);
System.out.println("");
System.out.println("cutover date is Date(Long.MAX_VALUE)");
System.out.println(" cutover year: " + year2);
System.out.println(" cutover era: " + era2);
} else {
System.out.println("test passed");
}
}
}
---------Output from the test---------------------
test failed
cutover date is Date(Long.MIN_VALUE)
cutover year: 292269055
cutover era: 0
cutover date is Date(Long.MAX_VALUE)
cutover year: 292269055
cutover era: 0
-------------------------------------------------
======================================================================
- relates to
-
JDK-5025560 (cal) doc: Calendar.getTime() and Calendar.getTimeInMills() spec desc needs clarification
- Open