|
Description
|
FULL PRODUCT VERSION :
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
customer Windows XP [version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
With the date "28-February-2007", when I use add(Calendar.MONTH, 1), the result is "28-March-2007" but not "31-March-2007". This is not coherent with the Javadoc of the class Calendar.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.util.Calendar;
import java.util.GregorianCalendar;
import junit.framework.TestCase;
/**
* @author Hong Nam NGUYEN -- Created: 4 oct. 07 - 10:38:28
*/
public class CalendarTest extends TestCase
{
final int MONTH = Calendar.MONTH;
final int DAY_OF_MONTH = Calendar.DAY_OF_MONTH;
static Calendar calendar = new GregorianCalendar();
static
{
calendar.clear();
calendar.set(2007, Calendar.JANUARY, 31);
}
public void testAdd1()
{
calendar.roll(MONTH, 1);
assertEquals("Should be February", Calendar.FEBRUARY, calendar.get(MONTH));
assertEquals("Should be 28", 28, calendar.get(DAY_OF_MONTH));
}
public void testAdd2()
{
calendar.roll(MONTH, 1);
assertEquals("Should be March", Calendar.MARCH, calendar.get(MONTH));
assertEquals("Should be 31", 31, calendar.get(DAY_OF_MONTH));
}
}
---------- END SOURCE ----------
Posted Date : 2007-10-10 08:11:42.0
|