This is the mail archive of the mauve-patches@sources.redhat.com mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

More calendar-test fixes


This removes 4 bad tests from gnu/java/util/Calendar/ampm.java

More specifically:
    checkTime(12, 0, Calendar.AM, "12:00 AM");
    checkTime(12, 10, Calendar.AM, "12:10 AM");
    checkTime(12, 0, Calendar.PM, "12:00 PM");
    checkTime(12, 10, Calendar.PM, "12:10 PM");

The first argument is what it sets the calendar to, which is matched
against the parsed date. The issue here is that the parsed time is 'h', 
i.e. 1-12 time and not 0-11 time.

0-11 time is:
0 AM (midnight), 1 AM, .. , 11 AM, midday = 0 PM, 1 PM .. 11 PM

1-12 time is:
12 AM (midnight), 1 AM, .. , 12 PM (midday), 1 PM, .. 11 PM

So what happens here is that setting the Calendar to 12 AM is an
overflow, which is handled due to leniency. 

E.g. "12 AM" = 11 AM + 1 hour = midday = 0 PM (0-based) or 12 PM
(1-based) which in any case does not match the expected output. 

Things get nastier because it also lead me to discover that 1)
Classpath's GregorianCalendar previously (and erroneously) was using
1-12 time, which I only discovered after fixing this due to a different
Mauve failure. And 2) I found that our SimpleDateFormat didn't
differentiate between parsing 1-based and 0-based hours. These two bugs
had previously cancelled each other out a lot of the time.

So even tests that turn out to be wrong can be helpful, just in places
you didn't expect. :)

So I'm happy to report now that (excluding these tests) I've got the
Calendar & friends in my tree down to a mere 3 Mauve failures, one of
which is not our fault (minimalDaysInFirstWeek data not available for
the UK locale in CLDR), one of which fails the same way as the JDK
(although the test seems justified), and one which is real, but isn't so
bad (MONTH & DAY_OF_YEAR conflict test).

/Sven
Index: gnu/testlet/java/util/Calendar/ampm.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/util/Calendar/ampm.java,v
retrieving revision 1.1
diff -u -r1.1 ampm.java
--- gnu/testlet/java/util/Calendar/ampm.java	27 Nov 2003 22:33:48 -0000	1.1
+++ gnu/testlet/java/util/Calendar/ampm.java	8 Mar 2005 02:36:55 -0000
@@ -25,18 +25,20 @@
     // 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");
+    // NOTE: Calendar uses a 0-11 time, 
+    // I.e. 0 AM (midnight), 1 AM, .. , 11 AM, midday = 0 PM, 1 PM .. 11 PM
+
+    // Whereas the 'h' flag is 1-12 time
+    // I.e. 12 AM (midnight), 1 AM, .. , 12 PM (midday), 1 PM, .. 11 PM
+
     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");

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]