[kaffe] Re: GregorianCalendar fixes
Ito Kazumitsu
kaz at maczuka.gcd.org
Thu Nov 27 08:08:02 PST 2003
Hi,
>>>>> ":" == Mark Wielaard <mark at klomp.org> writes:
:> Looked some more at the code and I see now that the the first change was
:> inside a if (time >= gregorianCutover) so it now makes more sense to me.
:> And the second change seems correct given the above remark.
:> I'll commit it in Classpath.
There is another difference between GNU Classpath's
java/util/GregorianCalendar.java and that of kaffe.
Kaffe's was imported from GNU Classpath and modified
in the kaffe world, as described by the following
ChangeLog entry.
2003-08-16 Guilhem Lavaux <guilhem at kaffe.org>
* java/util/GregorianCalendar.java (computeTime):
12:00 midnight is AM and 12:00 noon is PM.
Here is the patch that can be applied to Revision 1.21:
--- java/util/GregorianCalendar.java.orig Thu Nov 27 15:35:08 2003
+++ java/util/GregorianCalendar.java Thu Nov 27 15:48:25 2003
@@ -402,7 +402,11 @@
{
hour = fields[HOUR];
if (isSet[AM_PM] && fields[AM_PM] == PM)
- hour += 12;
+ if (hour != 12) /* not Noon */
+ hour += 12;
+ /* Fix the problem of the status of 12:00 AM (midnight). */
+ if (isSet[AM_PM] && fields[AM_PM] == AM && hour == 12)
+ hour = 0;
}
int minute = isSet[MINUTE] ? fields[MINUTE] : 0;
A mauve test attached. Since I have got a write access to the
mauve CVS registry, I will add it to the registry. The test
results shows that Sun's implementation also seems to have
something wrong.
Here is the output of the tests.
Kaffe + kaffe's GregorianCalendar
gnu.testlet.java.util.Calendar.ampm
----
PASS: gnu.testlet.java.util.Calendar.ampm (number 1)
PASS: gnu.testlet.java.util.Calendar.ampm (number 2)
PASS: gnu.testlet.java.util.Calendar.ampm (number 3)
PASS: gnu.testlet.java.util.Calendar.ampm (number 4)
PASS: gnu.testlet.java.util.Calendar.ampm (number 5)
PASS: gnu.testlet.java.util.Calendar.ampm (number 6)
PASS: gnu.testlet.java.util.Calendar.ampm (number 7)
PASS: gnu.testlet.java.util.Calendar.ampm (number 8)
PASS: gnu.testlet.java.util.Calendar.ampm (number 9)
PASS: gnu.testlet.java.util.Calendar.ampm (number 10)
PASS: gnu.testlet.java.util.Calendar.ampm (number 11)
PASS: gnu.testlet.java.util.Calendar.ampm (number 12)
PASS: gnu.testlet.java.util.Calendar.ampm (number 13)
PASS: gnu.testlet.java.util.Calendar.ampm (number 14)
PASS: gnu.testlet.java.util.Calendar.ampm (number 15)
PASS: gnu.testlet.java.util.Calendar.ampm (number 16)
0 of 16 tests failed
Kaffe + GNU Classpath's GregorianCalendar
gnu.testlet.java.util.Calendar.ampm
----
FAIL: gnu.testlet.java.util.Calendar.ampm (number 1)
got 12:00 PM but expected 12:00 AM
FAIL: gnu.testlet.java.util.Calendar.ampm (number 2)
got 12:00 PM but expected 12:00 AM
FAIL: gnu.testlet.java.util.Calendar.ampm (number 3)
got 12:10 PM but expected 12:10 AM
FAIL: gnu.testlet.java.util.Calendar.ampm (number 4)
got 12:10 PM but expected 12:10 AM
PASS: gnu.testlet.java.util.Calendar.ampm (number 5)
PASS: gnu.testlet.java.util.Calendar.ampm (number 6)
PASS: gnu.testlet.java.util.Calendar.ampm (number 7)
PASS: gnu.testlet.java.util.Calendar.ampm (number 8)
FAIL: gnu.testlet.java.util.Calendar.ampm (number 9)
got 12:00 AM but expected 12:00 PM
FAIL: gnu.testlet.java.util.Calendar.ampm (number 10)
got 12:00 AM but expected 12:00 PM
FAIL: gnu.testlet.java.util.Calendar.ampm (number 11)
got 12:10 AM but expected 12:10 PM
FAIL: gnu.testlet.java.util.Calendar.ampm (number 12)
got 12:10 AM but expected 12:10 PM
PASS: gnu.testlet.java.util.Calendar.ampm (number 13)
PASS: gnu.testlet.java.util.Calendar.ampm (number 14)
PASS: gnu.testlet.java.util.Calendar.ampm (number 15)
PASS: gnu.testlet.java.util.Calendar.ampm (number 16)
8 of 16 tests failed
Sun's java version "1.4.2_02"
gnu.testlet.java.util.Calendar.ampm
----
FAIL: gnu.testlet.java.util.Calendar.ampm (number 1)
got 12:00 PM but expected 12:00 AM
PASS: gnu.testlet.java.util.Calendar.ampm (number 2)
FAIL: gnu.testlet.java.util.Calendar.ampm (number 3)
got 12:10 PM but expected 12:10 AM
PASS: gnu.testlet.java.util.Calendar.ampm (number 4)
PASS: gnu.testlet.java.util.Calendar.ampm (number 5)
PASS: gnu.testlet.java.util.Calendar.ampm (number 6)
PASS: gnu.testlet.java.util.Calendar.ampm (number 7)
PASS: gnu.testlet.java.util.Calendar.ampm (number 8)
FAIL: gnu.testlet.java.util.Calendar.ampm (number 9)
got 12:00 AM but expected 12:00 PM
PASS: gnu.testlet.java.util.Calendar.ampm (number 10)
FAIL: gnu.testlet.java.util.Calendar.ampm (number 11)
got 12:10 AM but expected 12:10 PM
PASS: gnu.testlet.java.util.Calendar.ampm (number 12)
PASS: gnu.testlet.java.util.Calendar.ampm (number 13)
PASS: gnu.testlet.java.util.Calendar.ampm (number 14)
PASS: gnu.testlet.java.util.Calendar.ampm (number 15)
PASS: gnu.testlet.java.util.Calendar.ampm (number 16)
4 of 16 tests failed
The Mauve test program:
// Tags: JDK1.1
// Copyright (c) 2003 Ito Kazumitsu
// This file is part of Mauve.
package gnu.testlet.java.util.Calendar;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.text.*;
import java.util.*;
public class ampm implements Testlet
{
private DateFormat format;
private TestHarness harness;
public void test (TestHarness harness)
{
// AM/PM mark is locale-dependent. We use Locale.US.
format = new SimpleDateFormat("hh:mm a", Locale.US);
this.harness = harness;
// According to the API document of java.util.Calendar,
// midnight belongs to "am", and noon belongs to "pm".
checkTime(12, 0, Calendar.AM, "12:00 AM");
checkTime("12:00 AM", "12:00 AM");
checkTime(12, 10, Calendar.AM, "12:10 AM");
checkTime("12:10 AM", "12:10 AM");
checkTime(0, 0, Calendar.AM, "12:00 AM");
checkTime("0:00 AM", "12:00 AM");
checkTime(0, 10, Calendar.AM, "12:10 AM");
checkTime("0:10 AM", "12:10 AM");
checkTime(12, 0, Calendar.PM, "12:00 PM");
checkTime("12:00 PM", "12:00 PM");
checkTime(12, 10, Calendar.PM, "12:10 PM");
checkTime("12:10 PM", "12:10 PM");
checkTime(0, 0, Calendar.PM, "12:00 PM");
checkTime("0:00 PM", "12:00 PM");
checkTime(0, 10, Calendar.PM, "12:10 PM");
checkTime("0:10 PM", "12:10 PM");
}
private void checkTime(int hh, int mm, int ampm, String expect)
{
Calendar calendar = Calendar.getInstance();
calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR, hh);
calendar.set(Calendar.MINUTE, mm);
calendar.set(Calendar.AM_PM, ampm);
harness.check (format.format (calendar.getTime()), expect);
}
private void checkTime(String input, String expect)
{
Calendar calendar = Calendar.getInstance();
try
{
calendar.setTime (format.parse(input));
harness.check (format.format(calendar.getTime()), expect);
}
catch (ParseException _)
{
harness.debug (_);
harness.fail (input + " couldn't be parsed");
}
}
}
More information about the kaffe
mailing list