[cp-patches] [calendar] move field defaults into GregorianCalendar

Gary Benson gbenson at redhat.com
Fri Apr 13 08:21:13 UTC 2007


Hi again,

This commit moves the default values for undefined fields into
GregorianCalendar where they belong.  It's possible that these
need to be a little more fine-grained but this commit is a step
closer to what Sun does.

Cheers,
Gary
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.9239.2.2
diff -u -r1.9239.2.2 ChangeLog
--- ChangeLog	13 Apr 2007 07:54:27 -0000	1.9239.2.2
+++ ChangeLog	13 Apr 2007 08:11:36 -0000
@@ -1,3 +1,12 @@
+2007-04-13  Gary Benson  <gbenson at redhat.com>
+
+	* java/util/Calendar.java
+	(clear()): Zero cleared fields rather than using a default.
+	(clear(int)): Likewise.
+	* java/util/GregorianCalendar.java
+	(setDefaultFields): New method.
+	(computeTime): Call setDefaultFields if fields are not set.
+
 2007-04-13  Gary Benson  <gbenson at redhat.com>
 
 	* java/util/Calendar.java
Index: java/util/Calendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Calendar.java,v
retrieving revision 1.52.4.1
diff -u -r1.52.4.1 Calendar.java
--- java/util/Calendar.java	13 Apr 2007 07:54:29 -0000	1.52.4.1
+++ java/util/Calendar.java	13 Apr 2007 08:11:36 -0000
@@ -911,15 +911,11 @@
   {
     isTimeSet = false;
     areFieldsSet = false;
-    int zoneOffs = zone.getRawOffset();
-    int[] tempFields = 
-                       {
-                         1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, 0, 0, 0,
-                         0, 0, zoneOffs, 0
-                       };
-    fields = tempFields;
     for (int i = 0; i < FIELD_COUNT; i++)
-      isSet[i] = false;
+      {
+	fields[i] = 0;
+	isSet[i] = false;
+      }
   }
 
   /**
@@ -931,16 +927,11 @@
    */
   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
-                       };
     complete();
     isTimeSet = false;
     areFieldsSet = false;
     isSet[field] = false;
-    fields[field] = tempFields[field];
+    fields[field] = 0;
   }
 
   /**
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/GregorianCalendar.java,v
retrieving revision 1.49.4.1
diff -u -r1.49.4.1 GregorianCalendar.java
--- java/util/GregorianCalendar.java	12 Apr 2007 15:29:51 -0000	1.49.4.1
+++ java/util/GregorianCalendar.java	13 Apr 2007 08:11:36 -0000
@@ -496,6 +496,19 @@
   }
 
   /**
+   * Set all fields to their default values.
+   */
+  private void setDefaultFields()
+  {
+    int[] defaults = {
+      AD, 1970, JANUARY, 0, 0, 1, 0, -1, 1, AM, 0, 0, 0, 0, 0, 0, 0
+    };
+    System.arraycopy(defaults, 0, fields, 0, FIELD_COUNT);
+    fields[DAY_OF_WEEK] = getFirstDayOfWeek();
+    areFieldsSet = true;
+  }
+  
+  /**
    * Converts the time field values (<code>fields</code>) to
    * milliseconds since the epoch UTC (<code>time</code>).
    *
@@ -504,6 +517,9 @@
    */
   protected synchronized void computeTime()
   {
+    if (!areFieldsSet)
+      setDefaultFields();
+    
     int millisInDay = 0;
     int era = fields[ERA];
     int year = fields[YEAR];


More information about the Classpath-patches mailing list