-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2
-
beta2
-
x86
-
windows_nt
Name: rmT116609 Date: 09/28/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
Several calls to java.util.Calendar.set(int field, int value) may lead to
a wrong date, as shows the example below:
public class TestCalendar {
public static void main(String[] args){
try {
test();
} catch (Throwable e) {
e.printStackTrace();
}
try {
System.in.read();
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void test(){
Calendar cal = Calendar.getInstance();
System.out.println("cal.getTime() = " + cal.getTime());
cal.set(Calendar.WEEK_OF_YEAR,4);
System.out.println("cal.set(Calendar.WEEK_OF_YEAR,4);");
//(Uncommenting the next line cancels the bug:)
//System.out.println("cal.getTime() = " + cal.getTime());
cal.set(Calendar.DAY_OF_WEEK,2);
System.out.println("cal.set(Calendar.DAY_OF_WEEK,2);");
System.out.println("cal.getTime() = " + cal.getTime());
}
}
It yields the result:
cal.getTime() = Tue Sep 26 18:14:08 CEST 2000
cal.set(Calendar.WEEK_OF_YEAR,4);
cal.set(Calendar.DAY_OF_WEEK,2);
cal.getTime() = Mon Sep 25 18:14:08 CEST 2000
which is obviously not in week number 4.
(Review ID: 110046)
======================================================================