harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r494836 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/GregorianCalendar.java test/java/tests/api/java/util/GregorianCalendarTest.java
Date Wed, 10 Jan 2007 14:57:03 GMT
Author: tellison
Date: Wed Jan 10 06:57:02 2007
New Revision: 494836

URL: http://svn.apache.org/viewvc?view=rev&rev=494836
Log:
Apply patch HARMONY-2959 ([classlib][luni]GregorianCalendar.get(DAY_OF_YEAR) returns incorrect
value sometimes)

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=494836&r1=494835&r2=494836
==============================================================================
--- 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
Wed Jan 10 06:57:02 2007
@@ -760,10 +760,7 @@
         }
         if (days < 0) {
             year = year - 1;
-            days = days + 365 + (isLeapYear(year) ? 1 : 0);
-            if (year == changeYear && localTime < gregorianCutover) {
-                days -= julianError();
-            }
+            days = days + daysInYear(year);
         }
         fields[YEAR] = year;
         return (int) days + 1;
@@ -800,12 +797,12 @@
         return DaysInMonth[month];
     }
 
-    private int daysInYear() {
-        int daysInYear = isLeapYear(fields[YEAR]) ? 366 : 365;
-        if (fields[YEAR] == changeYear) {
+    private int daysInYear(int year) {
+        int daysInYear = isLeapYear(year) ? 366 : 365;
+        if (year == changeYear) {
             daysInYear -= currentYearSkew;
         }
-        if (fields[YEAR] == changeYear - 1) {
+        if (year == changeYear - 1) {
             daysInYear -= lastYearSkew;
         }
         return daysInYear;
@@ -885,7 +882,7 @@
             case DATE:
                 return daysInMonth();
             case DAY_OF_YEAR:
-                return daysInYear();
+                return daysInYear(fields[YEAR]);
             case DAY_OF_WEEK_IN_MONTH:
                 result = get(DAY_OF_WEEK_IN_MONTH)
                         + ((daysInMonth() - get(DATE)) / 7);
@@ -1117,7 +1114,7 @@
                 int days,
                 day;
                 if (field == WEEK_OF_YEAR) {
-                    days = daysInYear();
+                    days = daysInYear(fields[YEAR]);
                     day = DAY_OF_YEAR;
                 } else {
                     days = daysInMonth();
@@ -1148,7 +1145,7 @@
                 max = daysInMonth();
                 break;
             case DAY_OF_YEAR:
-                max = daysInYear();
+                max = daysInYear(fields[YEAR]);
                 break;
             case DAY_OF_WEEK:
                 max = maximums[field];

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=494836&r1=494835&r2=494836
==============================================================================
--- 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
Wed Jan 10 06:57:02 2007
@@ -631,6 +631,18 @@
         assertEquals(2, g1.get(Calendar.HOUR_OF_DAY));
         // End of regression test
     }
+    
+    /**
+     * @tests java.util.GregorianCalendar#get(int)
+     */
+    public void test_getI() { 
+        // Regression test for Hamrony-2959
+        Date date = new Date(Date.parse("Jan 15 00:00:01 GMT 2000")); 
+        GregorianCalendar gc = new GregorianCalendar(); 
+        gc.setGregorianChange(date); 
+        gc.setTimeInMillis(Date.parse("Dec 24 00:00:01 GMT 2000")); 
+        assertEquals(346, gc.get(Calendar.DAY_OF_YEAR)); 
+    }
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message