libgcj/6045: GregorianCalendar: getMinimum() and getMaximum() incorrect for month

msmith@spinnakernet.com msmith@spinnakernet.com
Fri Mar 22 17:36:00 GMT 2002


>Number:         6045
>Category:       libgcj
>Synopsis:       GregorianCalendar: getMinimum() and getMaximum() incorrect for month
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 22 17:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Michael Smith
>Release:        gcj (GCC) 3.1 20020322 (prerelease)
>Organization:
>Environment:
Linux msmith 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
>Description:
The Java API specification for Calendar describe Months as zero-based.  That means that getMinimum(Calendar.MONTH) should return 0.  However, gcj is reporting 1.  It would probably be ok for gcj to report 1 if it actually used 1 based months, but it's using 0 based months and still reporting 1 for getMinimum.  Same problems with getMaximum (11 vs 12).  
>How-To-Repeat:
[msmith@msmith cal]$ cat MonthMin.java
import java.util.Date;
import java.util.Calendar;

public class MonthMin {
    public static void main(String args[]) {

	Calendar cal = Calendar.getInstance();
	cal.setTime(new Date());

	int monthMin = cal.getMinimum(Calendar.MONTH);

	System.err.println("Minimum value for month: " + monthMin);

	// set the month to the minimum
	cal.set(Calendar.MONTH, monthMin);

	System.err.println("Month in this timestamp should be January: " + 
			   cal.getTime());

    }
}
[msmith@msmith cal]$ java -version
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
[msmith@msmith cal]$ javac MonthMin.java
[msmith@msmith cal]$ java MonthMin
Minimum value for month: 0
Month in this timestamp should be January: Tue Jan 22 20:23:35 EST 2002
[msmith@msmith cal]$ gcj --version
gcj (GCC) 3.1 20020322 (prerelease)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[msmith@msmith cal]$ gcj --main=MonthMin -o MonthMin MonthMin.java
[msmith@msmith cal]$ ./MonthMin 
Minimum value for month: 1
Month in this timestamp should be January: Fri Feb 22 20:23:57 GMT-05:00 2002
>Fix:
Index: GregorianCalendar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/GregorianCalendar.java,v
retrieving revision 1.15
diff -u -r1.15 GregorianCalendar.java
--- GregorianCalendar.java	2002/01/22 22:40:38	1.15
+++ GregorianCalendar.java	2002/03/23 01:30:31
@@ -917,11 +917,11 @@
   }
 
   private static final int[] minimums =
-      { BC,       1,  1,  0, 1,  1,   1,   SUNDAY, 1, 
+      { BC,       1,  0,  0, 1,  1,   1,   SUNDAY, 1, 
         AM,  1,  0,  1,  1,   1, -(12*60*60*1000),               0 };
 
   private static final int[] maximums =
-      { AD, 5000000, 12, 53, 5, 31, 366, SATURDAY, 5, 
+      { AD, 5000000, 11, 53, 5, 31, 366, SATURDAY, 5, 
         PM, 12, 23, 59, 59, 999, +(12*60*60*1000), (12*60*60*1000) };
 
   /**
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list