harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r496726 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/GregorianCalendar.java test/java/tests/api/java/util/GregorianCalendarTest.java
Date Tue, 16 Jan 2007 15:25:48 GMT
Author: hindessm
Date: Tue Jan 16 07:25:47 2007
New Revision: 496726

URL: http://svn.apache.org/viewvc?view=rev&rev=496726
Log:
Applying patches from "[#HARMONY-3003]
[classlib][luni]GregorianCalendar.get(Calendar.DAY_OF_MONTH) and
get(Calendar.MONTH) return incorrect value".

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java?view=diff&rev=496726&r1=496725&r2=496726
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
Tue Jan 16 07:25:47 2007
@@ -328,6 +328,9 @@
 
         int dayOfYear = computeYearAndDay(days, timeVal + zoneOffset);
         fields[DAY_OF_YEAR] = dayOfYear;
+        if(fields[YEAR] == changeYear && gregorianCutover < timeVal + zoneOffset){
+            dayOfYear += currentYearSkew;
+        }
         int month = dayOfYear / 32;
         boolean leapYear = isLeapYear(fields[YEAR]);
         int date = dayOfYear - daysInYear(leapYear, month);
@@ -356,6 +359,9 @@
                 dayOfYear = computeYearAndDay(days, timeVal - zoneOffset
                         + dstOffset);
                 fields[DAY_OF_YEAR] = dayOfYear;
+                if(fields[YEAR] == changeYear && gregorianCutover < timeVal -
zoneOffset + dstOffset){
+                    dayOfYear += currentYearSkew;
+                }
                 month = dayOfYear / 32;
                 leapYear = isLeapYear(fields[YEAR]);
                 date = dayOfYear - daysInYear(leapYear, month);
@@ -774,7 +780,13 @@
             if (year > changeYear) {
                 days -= ((year - 1901) / 100) - ((year - 1601) / 400);
             } else {
-                days += julianSkew;
+                if(year == changeYear){
+                    days += currentYearSkew;
+                }else if(year == changeYear -1){
+                    days += lastYearSkew;
+                }else{
+                    days += julianSkew;
+                }
             }
             return days;
         } else if (year <= changeYear) {
@@ -782,9 +794,8 @@
         }
         return (year - 1970) * 365 + ((year - 1972) / 4)
                 - ((year - 2000) / 100) + ((year - 2000) / 400);
-
     }
-
+    
     private int daysInMonth() {
         return daysInMonth(isLeapYear(fields[YEAR]), fields[MONTH]);
     }
@@ -1216,8 +1227,8 @@
         isCached = false;
         int dayOfYear = cal.get(DAY_OF_YEAR);
         if (dayOfYear < julianSkew) {
-            currentYearSkew = dayOfYear;
-            lastYearSkew = julianSkew - dayOfYear;
+            currentYearSkew = dayOfYear-1;
+            lastYearSkew = julianSkew - dayOfYear + 1;
         } else {
             lastYearSkew = 0;
             currentYearSkew = julianSkew;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java?view=diff&rev=496726&r1=496725&r2=496726
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
Tue Jan 16 07:25:47 2007
@@ -642,6 +642,14 @@
         gc.setGregorianChange(date); 
         gc.setTimeInMillis(Date.parse("Dec 24 00:00:01 GMT 2000")); 
         assertEquals(346, gc.get(Calendar.DAY_OF_YEAR)); 
+        
+        // Regression test for Harmony-3003
+        date = new Date(Date.parse("Feb 28 00:00:01 GMT 2000"));
+        gc = new GregorianCalendar();
+        gc.setGregorianChange(date);
+        gc.setTimeInMillis(Date.parse("Dec 1 00:00:01 GMT 2000"));
+        assertEquals(1, gc.get(Calendar.DAY_OF_MONTH));
+        assertEquals(11, gc.get(Calendar.MONTH));
     }
 
 	/**



Mime
View raw message