[kaffe] CVS kaffe (robilad): Sven's fix for date format/calendar problem

Kaffe CVS cvs-commits at kaffe.org
Sat Feb 5 12:42:15 PST 2005


PatchSet 5979 
Date: 2005/02/05 20:36:22
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Sven's fix for date format/calendar problem

2005-02-05  Sven de Marothy  <sven at physto.se>

        * java/text/SimpleDateFormat.java
        (parse): Tweak handling of 2-year dates
        * java/util/Calendar.java
        (clear): Clear fields to correct value.
        * java/util/GregorianCalendar.java
        (computeTime): Correct handling of time zones.
        Correct field minimum values.

Members: 
	ChangeLog:1.3517->1.3518 
	libraries/javalib/java/text/SimpleDateFormat.java:1.43->1.44 
	libraries/javalib/java/util/Calendar.java:1.31->1.32 
	libraries/javalib/java/util/GregorianCalendar.java:1.34->1.35 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3517 kaffe/ChangeLog:1.3518
--- kaffe/ChangeLog:1.3517	Sat Feb  5 19:41:58 2005
+++ kaffe/ChangeLog	Sat Feb  5 20:36:22 2005
@@ -1,3 +1,13 @@
+2005-02-05  Sven de Marothy  <sven at physto.se>
+
+	* java/text/SimpleDateFormat.java
+	(parse): Tweak handling of 2-year dates
+	* java/util/Calendar.java
+	(clear): Clear fields to correct value.
+	* java/util/GregorianCalendar.java
+	(computeTime): Correct handling of time zones.
+	Correct field minimum values.
+
 2005-02-05  Dalibor Topic  <robilad at kaffe.org>
 
 	* configure.ac: Don't add PTHREAD_CFLAGS to CFLAGS.
Index: kaffe/libraries/javalib/java/text/SimpleDateFormat.java
diff -u kaffe/libraries/javalib/java/text/SimpleDateFormat.java:1.43 kaffe/libraries/javalib/java/text/SimpleDateFormat.java:1.44
--- kaffe/libraries/javalib/java/text/SimpleDateFormat.java:1.43	Thu Feb  3 17:01:25 2005
+++ kaffe/libraries/javalib/java/text/SimpleDateFormat.java	Sat Feb  5 20:36:28 2005
@@ -1096,7 +1096,10 @@
 		// exactly 2 digits.
 		int digit_count = pos.getIndex() - index;
 		if (digit_count == 2)
-		  is2DigitYear = true;
+		  {
+		    is2DigitYear = true;
+		    value += defaultCentury;
+		  }
 	      }
 	    
 	    // Assign the value and move on.
@@ -1107,8 +1110,7 @@
 	  {
 	    // Apply the 80-20 heuristic to dermine the full year based on 
 	    // defaultCenturyStart. 
-	    int year = defaultCentury + calendar.get(Calendar.YEAR);
-	    calendar.set(Calendar.YEAR, year);
+	    int year = calendar.get(Calendar.YEAR);
 	    if (calendar.getTime().compareTo(defaultCenturyStart) < 0)
 	      calendar.set(Calendar.YEAR, year + 100);      
 	  }
Index: kaffe/libraries/javalib/java/util/Calendar.java
diff -u kaffe/libraries/javalib/java/util/Calendar.java:1.31 kaffe/libraries/javalib/java/util/Calendar.java:1.32
--- kaffe/libraries/javalib/java/util/Calendar.java:1.31	Thu Feb  3 17:01:25 2005
+++ kaffe/libraries/javalib/java/util/Calendar.java	Sat Feb  5 20:36:29 2005
@@ -683,7 +683,7 @@
     fields[field] = value;
     isSet[field] = true;
 
-    // The five valid date patterns, in order of validity
+    // The five valid date patterns, in order of priority
     // 1  YEAR + MONTH + DAY_OF_MONTH
     // 2  YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
     // 3  YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
@@ -827,23 +827,21 @@
   {
     isTimeSet = false;
     areFieldsSet = false;
+    int zoneOffs = zone.getRawOffset();
 
-    int hour = fields[ZONE_OFFSET] / (60 * 60 * 1000);
-    int minute = (fields[ZONE_OFFSET] - 60 * 60 * 1000 * hour) / (60 * 1000);
-    int seconds = (fields[ZONE_OFFSET] - 60 * 60 * 1000 * hour
-                  - 60 * 1000 * minute) / 1000;
-    int millis = fields[ZONE_OFFSET] - 60 * 60 * 1000 * hour
-                 - 60 * 1000 * minute - seconds * 1000;
+    int hour = zoneOffs / (60 * 60 * 1000);
+    int minute = (zoneOffs - 60 * 60 * 1000 * hour) / (60 * 1000);
+    int seconds = (zoneOffs - 60 * 60 * 1000 * hour - 60 * 1000 * minute) / 1000;
+    int millis = zoneOffs - 60 * 60 * 1000 * hour - 60 * 1000 * minute
+                 - seconds * 1000;
     int[] tempFields = 
                        {
                          1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, hour,
-                         hour, minute, seconds, millis, fields[ZONE_OFFSET],
-                         fields[DST_OFFSET]
+                         hour, minute, seconds, millis, zoneOffs, 0
                        };
     fields = tempFields;
-    for (int i = 0; i < FIELD_COUNT - 2; i++)
+    for (int i = 0; i < FIELD_COUNT; i++)
       isSet[i] = false;
-    isSet[ZONE_OFFSET] = isSet[DST_OFFSET] = true;
   }
 
   /**
@@ -855,10 +853,15 @@
    */
   public final void clear(int field)
   {
+    int[] tempFields = 
+                       {
+                         1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, 0, 0, 0,
+                         0, 0, zone.getRawOffset(), 0
+                       };
     isTimeSet = false;
     areFieldsSet = false;
     isSet[field] = false;
-    fields[field] = 0;
+    fields[field] = tempFields[field];
   }
 
   /**
Index: kaffe/libraries/javalib/java/util/GregorianCalendar.java
diff -u kaffe/libraries/javalib/java/util/GregorianCalendar.java:1.34 kaffe/libraries/javalib/java/util/GregorianCalendar.java:1.35
--- kaffe/libraries/javalib/java/util/GregorianCalendar.java:1.34	Thu Feb  3 17:01:25 2005
+++ kaffe/libraries/javalib/java/util/GregorianCalendar.java	Sat Feb  5 20:36:29 2005
@@ -562,18 +562,18 @@
     // rest of code assumes day/month/year set
     // should negative BC years be AD?
     // get the hour (but no check for validity)
-    if (isSet[HOUR_OF_DAY])
-      hour = fields[HOUR_OF_DAY];
-    else if (isSet[HOUR])
+    if (isSet[HOUR])
       {
 	hour = fields[HOUR];
-	if (isSet[AM_PM] && fields[AM_PM] == PM)
+	if (fields[AM_PM] == PM)
 	  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)
+	if (fields[AM_PM] == AM && hour == 12)
 	  hour = 0;
       }
+    else
+      hour = fields[HOUR_OF_DAY];
 
     // Read the era,year,month,day fields and convert as appropriate.
     // Calculate number of milliseconds into the day
@@ -644,12 +644,20 @@
       weekday += 7;
     fields[DAY_OF_WEEK] = weekday;
 
+    // Time zone corrections.
     TimeZone zone = getTimeZone();
-    int rawOffset = zone.getRawOffset();
-    int dstOffset = zone.getOffset((year < 1) ? BC : AD,
-                                   (year < 1) ? 1 - year : year, month, day,
-                                   weekday, millisInDay) - zone.getRawOffset();
-    time -= (rawOffset + dstOffset);
+    int rawOffset = isSet[ZONE_OFFSET] ? fields[ZONE_OFFSET]
+                                       : zone.getRawOffset();
+
+    int dstOffset = isSet[DST_OFFSET] ? fields[DST_OFFSET]
+                                      : (zone.getOffset((year < 0) ? BC : AD,
+                                                        (year < 0) ? 1 - year
+                                                                   : year,
+                                                        month, day, weekday,
+                                                        millisInDay)
+                                      - zone.getRawOffset());
+
+    time -= rawOffset + dstOffset;
 
     isTimeSet = true;
   }
@@ -1101,7 +1109,7 @@
   private static final int[] minimums = 
                                         {
                                           BC, 1, 0, 0, 1, 1, 1, SUNDAY, 1, AM,
-                                          1, 0, 1, 1, 1, -(12 * 60 * 60 * 1000),
+                                          1, 0, 0, 0, 0, -(12 * 60 * 60 * 1000),
                                           0
                                         };
 



More information about the kaffe mailing list