This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

Patch: Calendar fixes


This patch fixes some small Calendar problems, including the DST rollover issue reported by Martin Egholm Nielsen. Calendar.set did not invalidate the DST_OFFSET field even though changing other fields could roll the time over a DST boundary. Thus, computeTime() would apply the DST offset to the resulting Date value even if the date was no longer in a DST period. I've checked in a mauve test for this issue. Also, this patch contains a minor spec fix for GregorianCalendar.add().

Bryce


2004-10-08  Bryce McKinlay  <mckinlay@redhat.com>

	* java/util/Calendar.java (set): Invalidate DST_OFFSET
	field as a DST boundary may have been crossed.
	* java/util/GregorianCalendar.java (add): Throw 
	IllegalArgumentException on attempt to add to DST_OFFSET or 
	ZONE_OFFSET fields. Update javadoc.

Index: Calendar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/Calendar.java,v
retrieving revision 1.23
diff -u -r1.23 Calendar.java
--- Calendar.java	29 Aug 2004 17:28:09 -0000	1.23
+++ Calendar.java	8 Oct 2004 23:22:17 -0000
@@ -651,6 +651,10 @@
 	isSet[HOUR_OF_DAY] = false;
 	break;
       }
+
+    // May have crossed over a DST boundary.
+    if (field != DST_OFFSET && field != ZONE_OFFSET)
+      isSet[DST_OFFSET] = false;
   }
 
   /**
@@ -671,6 +675,8 @@
     isSet[WEEK_OF_MONTH] = false;
     isSet[DAY_OF_WEEK] = false;
     isSet[DAY_OF_WEEK_IN_MONTH] = false;
+
+    isSet[DST_OFFSET] = false;  // May have crossed a DST boundary.
   }
 
   /**
Index: GregorianCalendar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/GregorianCalendar.java,v
retrieving revision 1.22
diff -u -r1.22 GregorianCalendar.java
--- GregorianCalendar.java	10 Jul 2004 02:23:40 -0000	1.22
+++ GregorianCalendar.java	8 Oct 2004 23:22:17 -0000
@@ -540,7 +540,7 @@
     fields[DAY_OF_WEEK] = weekday;
 
     // get a first approximation of the year.  This may be one 
-    // year to big.
+    // year too big.
     int year = 1970 + (gregorian
 		       ? ((day - 100) * 400) / (365 * 400 + 100 - 4 + 1)
 		       : ((day - 100) * 4) / (365 * 4 + 1));
@@ -709,6 +709,10 @@
    * it does what you expect: Jan, 25 + 10 Days is Feb, 4.
    * @param field the time field. One of the time field constants.
    * @param amount the amount of time.
+   * @exception IllegalArgumentException if <code>field</code> is 
+   *   <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or invalid; or
+   *   if <code>amount</code> contains an out-of-range value and the calendar
+   *   is not in lenient mode.
    */
   public void add(int field, int amount)
   {
@@ -785,18 +789,9 @@
 	areFieldsSet = false;
 	break;
       case ZONE_OFFSET:
-	complete();
-	fields[ZONE_OFFSET] += amount;
-	time -= amount;
-	break;
       case DST_OFFSET:
-	complete();
-	fields[DST_OFFSET] += amount;
-	isTimeSet = false;
-	break;
       default:
-	throw new IllegalArgumentException
-	  ("Unknown Calendar field: " + field);
+	throw new IllegalArgumentException("Invalid or unknown field");
       }
   }
 

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