Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6615044
Votes 0
Synopsis (cal) The Calendar.add(int field, int amount) does NOT work like expected
Category java:classes_util_i18n
Reported Against
Release Fixed
State 3-Accepted, bug
Priority: 4-Low
Related Bugs
Submit Date 10-OCT-2007
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
Work Around
N/A
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang