-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.1.8
-
sparc
-
solaris_2.5
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2022869 | 1.2.0 | Alan Liu | P3 | Closed | Fixed | 1.2fcs |
Name: dfC67450 Date: 09/17/98
If we add 11 months to Feb-29-1996 we should obtain Jan-29-1997 but
we obtain Jan-28-1997.
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(1996, 1, 29);
System.out.println("init date: " + calendar.getTime());
System.out.println();
calendar.add(Calendar.MONTH, 10);
Date date1 = calendar.getTime();
int d1 = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("after adding 10 months: " + date1);
calendar = new GregorianCalendar(1996, 1, 29);
calendar.add(Calendar.MONTH, 11);
Date date2 = calendar.getTime();
int d2 = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("after adding 11 months: " + date2);
if (d1 == d2) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
}
}
}
---------Output from the test---------------------
init date: Thu Feb 29 00:00:00 GMT+03:00 1996
after adding 10 months: Sun Dec 29 00:00:00 GMT+03:00 1996
after adding 11 months: Tue Jan 28 00:00:00 GMT+03:00 1997
Test failed
-------------------------------------------------
This bug arised after bug 4165343 has been fixed.
======================================================================
If we add 11 months to Feb-29-1996 we should obtain Jan-29-1997 but
we obtain Jan-28-1997.
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(1996, 1, 29);
System.out.println("init date: " + calendar.getTime());
System.out.println();
calendar.add(Calendar.MONTH, 10);
Date date1 = calendar.getTime();
int d1 = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("after adding 10 months: " + date1);
calendar = new GregorianCalendar(1996, 1, 29);
calendar.add(Calendar.MONTH, 11);
Date date2 = calendar.getTime();
int d2 = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("after adding 11 months: " + date2);
if (d1 == d2) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
}
}
}
---------Output from the test---------------------
init date: Thu Feb 29 00:00:00 GMT+03:00 1996
after adding 10 months: Sun Dec 29 00:00:00 GMT+03:00 1996
after adding 11 months: Tue Jan 28 00:00:00 GMT+03:00 1997
Test failed
-------------------------------------------------
This bug arised after bug 4165343 has been fixed.
======================================================================
- backported by
-
JDK-2022869 GregorianCalendar.add(int field, int amount) works wrong on Feb-29
- Closed