[kaffe] Re: GregorianCalendar fixes

Ito Kazumitsu kaz at maczuka.gcd.org
Fri Dec 26 10:20:05 PST 2003


Hi,

>>>>> ":" == Mark Wielaard <mark at klomp.org> writes:

:> There is only one functional change left between kaffe and classpath in
:> computeFields():

:> -    fields[DAY_OF_WEEK_IN_MONTH] = (fields[DAY_OF_MONTH] + 12) / 7;
:> +    fields[DAY_OF_WEEK_IN_MONTH] = (fields[DAY_OF_MONTH] + 6) / 7;

:> Haven't looked at who is right here, so won't merge.

This change about DAY_OF_WEEK_IN_MONTH was in Mark's patch [1] (see below)
but was not in my original patch [2] (see below) posted to the kaffe mailing
list.  This patch seemes to have been introduced by analogy with the
patch about WEEK_OF_MONTH. 

But Sun's API document says:

    Unlike WEEK_OF_MONTH and WEEK_OF_YEAR, this field's value does not
    depend on getFirstDayOfWeek() or getMinimalDaysInFirstWeek().
    DAY_OF_MONTH 1 through 7 always correspond to DAY_OF_WEEK_IN_MONTH 1;
    8 through 14 correspond to DAY_OF_WEEK_IN_MONTH 2, and so on.

In this respect,

    fields[DAY_OF_WEEK_IN_MONTH] = (fields[DAY_OF_MONTH] + 6) / 7;

seems to be correct.

[1]====================
From: Mark Wielaard <mark at klomp.org>
To: classpath at gnu.org, kaffe at kaffe.org
Message-Id: <1069431275.2861.580.camel at elsschot.wildebeest.org>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 
Date: Fri, 21 Nov 2003 17:14:35 +0100
Cc: java-patches at gcc.gnu.org
Subject: GregorianCalendar fixes
X-BeenThere: classpath at gnu.org
X-Mailman-Version: 2.1.2
List-Unsubscribe: <http://mail.gnu.org/mailman/listinfo/classpath>,	<mailto:classpath-request at gnu.org?subject=unsubscribe>
List-Archive: <http://mail.gnu.org/pipermail/classpath>
List-Post: <mailto:classpath at gnu.org>
List-Help: <mailto:classpath-request at gnu.org?subject=help>
List-Subscribe: <http://mail.gnu.org/mailman/listinfo/classpath>,	<mailto:classpath-request at gnu.org?subject=subscribe>

[1  <multipart/signed (7bit)>]
[1.1  <multipart/mixed (7bit)>]
[1.1.1  <text/plain (quoted-printable)>]
Hi,

Since I am not a GregorianCalendar expert I was hoping that someone
could review the following patch which I have in my tree from Ito
Kazumitsu. He and I wrote a couple of mauve test cases which are fixed
by this and I see no new failures. But people didn't seem to be
completely comfortable with it back in Augustus/September. It would be
nice if we could create even more test cases to make sure that nothing
else breaks and to have a ChangeLog entry for this patch (Ito?). Don't
really have have time to learn about Calendars so I am just re-posting
this patch in the hope that someone can review it.

Thanks,

Mark
[1.1.2 GregorianCalendar.patch <text/x-patch; ISO-8859-1 (base64)>]
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/GregorianCalendar.java,v
retrieving revision 1.20
diff -u -r1.20 GregorianCalendar.java
--- java/util/GregorianCalendar.java	12 Aug 2003 13:41:27 -0000	1.20
+++ java/util/GregorianCalendar.java	21 Nov 2003 16:11:56 -0000
@@ -1,5 +1,5 @@
 /* java.util.GregorianCalendar
-   Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -264,8 +264,10 @@
 	//
 	// The additional leap year factor accounts for the fact that
 	// a leap day is not seen on Jan 1 of the leap year.
+	// And on and after the leap day, the leap day has already been
+	// included in dayOfYear. 
 	int gregOffset = (year / 400) - (year / 100) + 2;
-	if (isLeapYear (year, true) && dayOfYear < 31 + 29)
+	if (isLeapYear (year, true))
 	  --gregOffset;
 	time += gregOffset * (24 * 60 * 60 * 1000L);
       }
@@ -604,12 +606,12 @@
 	calculateDay(++day, gregorian);
       }
 
-    fields[DAY_OF_WEEK_IN_MONTH] = (fields[DAY_OF_MONTH] + 6) / 7;
+    fields[DAY_OF_WEEK_IN_MONTH] = (fields[DAY_OF_MONTH] + 12) / 7;
 
     // which day of the week are we (0..6), relative to getFirstDayOfWeek
     int relativeWeekday = (7 + fields[DAY_OF_WEEK] - getFirstDayOfWeek()) % 7;
 
-    fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH] - relativeWeekday + 6) / 7;
+    fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH] - relativeWeekday + 12) / 7;
 
     int weekOfYear = (fields[DAY_OF_YEAR] - relativeWeekday + 6) / 7;
 
[1.2 This is a digitally signed message part <application/pgp-signature (7bit)>]

[2  <text/plain; us-ascii (7bit)>]
_______________________________________________
Classpath mailing list
Classpath at gnu.org
http://mail.gnu.org/mailman/listinfo/classpath

[2]=================================================================
From: Ito Kazumitsu <ito.kazumitsu at hitachi-cable.co.jp>
To: kaffe at kaffe.org
In-reply-to: Ito Kazumitsu's message of "Mon, 28 Jul 2003 10:46:11 +0900"	<200307280146.h6S1kBq16305 at sm1.hitachi-cable.co.jp>
Subject: Re: [kaffe] Bug in Kaffe 1.0.7
User-Agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.3 (Unebigoryōmae)
 APEL/10.3 Emacs/20.7 (i386-*-windows98.2222) MULE/4.1 (AOI) Meadow/1.14
 (AWSAKA:62)
MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya")
X-BeenThere: kaffe at kaffe.org
X-Mailman-Version: 2.0.11
List-Help: <mailto:kaffe-request at kaffe.org?subject=help>
List-Post: <mailto:kaffe at kaffe.org>
List-Subscribe: <http://kaffe.org/cgi-bin/mailman/listinfo/kaffe>,	<mailto:kaffe-request at kaffe.org?subject=subscribe>
List-Unsubscribe: <http://kaffe.org/cgi-bin/mailman/listinfo/kaffe>,	<mailto:kaffe-request at kaffe.org?subject=unsubscribe>
List-Archive: <http://kaffe.org/pipermail/kaffe/>
X-Original-Date: Mon, 28 Jul 2003 13:31:38 +0900
Date: Mon, 28 Jul 2003 13:31:38 +0900


In message "Re: [kaffe] Bug in Kaffe 1.0.7"
    on 03/07/28, Ito Kazumitsu <ito.kazumitsu at hitachi-cable.co.jp> writes:

> The attached program prints week-related values for the dates
> from Jan 1 2000 to Dec 31 2003.  Both GNU Classpath and Sun's
> JDK give identical results for the following months:
> 
>    Oct 2000, Apr 2001, Jul 2001, Sep 2002, Dec 2002, Jun 2003

These months are special in that the first day of the month is Sunday.

The attached patch makes GNU classpath's java.util.Calendar behave
almost similarly to Sun's JDK except that the former returns 53 or
54 as the last week of the year but the latter returns 1.   I think
that returning 1 as the last week of the year may be a bug of Sun's
JDK.

I will submit this patch to the GNU Classpath mailing list.

--- java/util/GregorianCalendar.java.orig	Sun Mar 24 01:10:15 2002
+++ java/util/GregorianCalendar.java	Mon Jul 28 11:53:16 2003
@@ -599,7 +599,7 @@
     // which day of the week are we (0..6), relative to getFirstDayOfWeek
     int relativeWeekday = (7 + fields[DAY_OF_WEEK] - getFirstDayOfWeek()) % 7;
 
-    fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH] - relativeWeekday + 6) / 7;
+    fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH] - relativeWeekday + 12) / 7;
 
     int weekOfYear = (fields[DAY_OF_YEAR] - relativeWeekday + 6) / 7;
 

_______________________________________________
kaffe mailing list
kaffe at kaffe.org
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe




More information about the kaffe mailing list