[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: Calendaring fixes from Sven

Kaffe CVS cvs-commits at kaffe.org
Mon Feb 14 13:41:35 PST 2005


PatchSet 5544 
Date: 2005/02/14 21:36:01
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: Calendaring fixes from Sven

2005-02-14  Dalibor Topic  <robilad at kaffe.org>

Resynced with GNU Classpath.

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

        * java/util/Calendar.java
        (Calendar): Constructor should clear fields.

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

        * java/util/Calendar.java
        (clear): Dates should clear to local time.

        * java/util/GregorianCalendar.java
        (computeTime): Fix priority problem with DAY_OF_WEEK,
        Handle non-sunday-startig weeks and minimumDaysInFirstWeek.

Members: 
	ChangeLog:1.3588->1.3589 
	libraries/javalib/java/util/Calendar.java:1.32->1.33 
	libraries/javalib/java/util/GregorianCalendar.java:1.35->1.36 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3588 kaffe/ChangeLog:1.3589
--- kaffe/ChangeLog:1.3588	Mon Feb 14 21:19:57 2005
+++ kaffe/ChangeLog	Mon Feb 14 21:36:01 2005
@@ -2,6 +2,24 @@
 
 	Resynced with GNU Classpath.
 	
+	2005-02-14  Sven de Marothy  <sven at physto.se>
+
+        * java/util/Calendar.java 
+        (Calendar): Constructor should clear fields.
+
+	2005-02-14  Sven de Marothy  <sven at physto.se>
+
+        * java/util/Calendar.java 
+        (clear): Dates should clear to local time.
+
+        * java/util/GregorianCalendar.java      
+        (computeTime): Fix priority problem with DAY_OF_WEEK,
+        Handle non-sunday-startig weeks and minimumDaysInFirstWeek.
+
+2005-02-14  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+	
 	2005-02-13  Mark Wielaard  <mark at klomp.org>
 
 	* java/awt/AWTKeyStroke.java (getAWTKeyStroke(String)): Throw
Index: kaffe/libraries/javalib/java/util/Calendar.java
diff -u kaffe/libraries/javalib/java/util/Calendar.java:1.32 kaffe/libraries/javalib/java/util/Calendar.java:1.33
--- kaffe/libraries/javalib/java/util/Calendar.java:1.32	Sat Feb  5 20:36:29 2005
+++ kaffe/libraries/javalib/java/util/Calendar.java	Mon Feb 14 21:36:06 2005
@@ -454,6 +454,7 @@
     firstDayOfWeek = ((Integer) rb.getObject("firstDayOfWeek")).intValue();
     minimalDaysInFirstWeek = ((Integer) rb.getObject("minimalDaysInFirstWeek"))
                              .intValue();
+    clear();
   }
 
   /**
@@ -828,16 +829,10 @@
     isTimeSet = false;
     areFieldsSet = false;
     int zoneOffs = zone.getRawOffset();
-
-    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, zoneOffs, 0
+                         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++)
Index: kaffe/libraries/javalib/java/util/GregorianCalendar.java
diff -u kaffe/libraries/javalib/java/util/GregorianCalendar.java:1.35 kaffe/libraries/javalib/java/util/GregorianCalendar.java:1.36
--- kaffe/libraries/javalib/java/util/GregorianCalendar.java:1.35	Sat Feb  5 20:36:29 2005
+++ kaffe/libraries/javalib/java/util/GregorianCalendar.java	Mon Feb 14 21:36:06 2005
@@ -369,8 +369,25 @@
   private int getFirstDayOfMonth(int year, int month)
   {
     int[] dayCount = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
-    int dayOfYear = dayCount[month] + 1;
 
+    if (month > 11)
+      {
+	year += (month / 12);
+	month = month % 12;
+      }
+
+    if (month < 0)
+      {
+	year += (int) month / 12;
+	month = month % 12;
+	if (month < 0)
+	  {
+	    month += 12;
+	    year--;
+	  }
+      }
+
+    int dayOfYear = dayCount[month] + 1;
     if (month > 1)
       if (isLeapYear(year))
 	dayOfYear++;
@@ -508,22 +525,28 @@
     if (! isLenient())
       nonLeniencyCheck();
 
-    if (! isSet[MONTH])
+    if (! isSet[MONTH] && (! isSet[DAY_OF_WEEK] || isSet[WEEK_OF_YEAR]))
       {
 	// 5: YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
-	if (isSet[DAY_OF_WEEK] || isSet[WEEK_OF_YEAR])
+	if (isSet[WEEK_OF_YEAR])
 	  {
 	    int first = getFirstDayOfMonth(year, 0);
-	    int offs;
-	    if ((8 - first) >= getMinimalDaysInFirstWeek())
-	      // start counting on first week
-	      offs = 1;
-	    else
-	      offs = 1 + (8 - first);
+	    int offs = 1;
+	    int daysInFirstWeek = getFirstDayOfWeek() - first;
+	    if (daysInFirstWeek <= 0)
+	      daysInFirstWeek += 7;
 
+	    if (daysInFirstWeek < getMinimalDaysInFirstWeek())
+	      offs += daysInFirstWeek;
+	    else
+	      offs -= 7 - daysInFirstWeek;
 	    month = 0;
 	    day = offs + 7 * (fields[WEEK_OF_YEAR] - 1);
-	    day += fields[DAY_OF_WEEK] - first;
+	    offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
+
+	    if (offs < 0)
+	      offs += 7;
+	    day += offs;
 	  }
 	else
 	  {
@@ -549,8 +572,21 @@
 	      }
 	    else
 	      { // 2: YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
-		day = 1 + 7 * (fields[WEEK_OF_MONTH] - 1);
-		day += fields[DAY_OF_WEEK] - first;
+		int offs = 1;
+		int daysInFirstWeek = getFirstDayOfWeek() - first;
+		if (daysInFirstWeek <= 0)
+		  daysInFirstWeek += 7;
+
+		if (daysInFirstWeek < getMinimalDaysInFirstWeek())
+		  offs += daysInFirstWeek;
+		else
+		  offs -= 7 - daysInFirstWeek;
+
+		day = offs + 7 * (fields[WEEK_OF_MONTH] - 1);
+		offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
+		if (offs < 0)
+		  offs += 7;
+		day += offs;
 	      }
 	  }
 



More information about the kaffe mailing list