JDK-4514831 : GregorianCalendar, can't roll date from 10/28/2001 to 10/29/2001
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_98
  • CPU: x86
  • Submitted: 2001-10-15
  • Updated: 2002-04-29
  • Resolved: 2002-04-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 hopperFixed
Related Reports
Relates :  
Description

Name: bsT130419			Date: 10/15/2001

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)


Hi, I'm using the GregorianCalendar class from the jav.util package and have
had a small problem.  When I run the code below, the calendar doesn't seem to
want to roll the date from 10/28/2001 to the next day. The code however works
for any other starting date except 10/28/2001.  The output of the code is:
"28-28 28-29 29-30 30-31 31-1 1-2 2-3"

import java.io.*;
import java.util.*;

import javax.servlet.http.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletException;

public class test extends HttpServlet
{
	public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
	{
               GregorianCalendar c = new GegorianCalendar(2001,9,28);
		
                String test="";
		for(int i=0; i<7; i++)
		{
		test+=c.get(c.DAY_OF_MONTH) + "-";
		c.roll(c.DAY_OF_YEAR, true);
		test+=c.get(c.DAY_OF_MONTH) + "";
			
		test += "   ";
		}
	PrintWriter out = response.getWriter();
	response.setContentType("text/html");
	out.print(test);
	}
}


Thanks for any help.

Dan
(Review ID: 133716) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper FIXED IN: hopper INTEGRATED IN: hopper
14-06-2004

WORK AROUND Name: bsT130419 Date: 10/15/2001 When date is 10/28/2001, instead of rolling the date, just set the date to 10/29/2001. ====================================================================== Specify clock time after the DST transition, such as 6:00am in a U.S. time zone. The following program demonstrates this workaround. -- import java.util.*; class Test { public static void main(String[] args) { GregorianCalendar c1 = new GregorianCalendar(2001,9,1, 6, 0, 0); // 6:00am System.out.println(c1.getTime()); System.out.println("MONTH: " + c1.get(c1.MONTH)); String s1=""; for(int i=0; i<30; i++) { s1 += c1.get(c1.DAY_OF_MONTH) + "-"; c1.roll(c1.DAY_OF_YEAR, true); s1 += c1.get(c1.DAY_OF_MONTH) + ""; s1 += " "; } System.out.println(s1); System.out.println(c1.getTime()); } } -- $ /usr/local/java/jdk1.4/solsparc/bin/java Test Mon Oct 01 06:00:00 PDT 2001 MONTH: 9 1-2 2-3 3-4 4-5 5-6 6-7 7-8 8-9 9-10 10-11 11-12 12-13 13-14 14-15 15-16 16-17 17-18 18-19 19-20 20-21 21-22 22-23 23-24 24-25 25-26 26-27 27-28 28-29 29-30 30-31 Wed Oct 31 05:00:00 PST 2001
11-06-2004

EVALUATION This is a side effect of daylight saving adjustment. ###@###.### 2001-10-15 In roll(), a fixed length of time, such as a day, is converted to milliseconds for date calculation. So adding 24 hours to 10/28/2001 0:00 (daylight time) produces 10/28/2001 23:00 (standard time). See also bug# 4312621. ###@###.### 2001-10-16 add() adjusts daylight saving time changes. ###@###.### 2002-01-23
16-10-2001