harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r494772 - 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 09:06:42 GMT
Author: liangyx
Date: Wed Jan 10 01:06:41 2007
New Revision: 494772

URL: http://svn.apache.org/viewvc?view=rev&rev=494772
Log:
Apply patch for HARMONY-2954 ([classlib][luni]GregorianCalendar.getActualMaximum(Calendar.DAY_OF_YEAR)
returns 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=494772&r1=494771&r2=494772
==============================================================================
--- 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 01:06:41 2007
@@ -74,6 +74,10 @@
 
     private long lastMidnightMillis = 0L;
 
+    private int currentYearSkew = 10;
+
+    private int lastYearSkew = 0;
+
     /**
      * Constructs a new GregorianCalendar initialized to the current date and
      * time.
@@ -796,7 +800,14 @@
     }
 
     private int daysInYear() {
-        return isLeapYear(fields[YEAR]) ? 366 : 365;
+        int daysInYear = isLeapYear(fields[YEAR]) ? 366 : 365;
+        if (fields[YEAR] == changeYear) {
+            daysInYear -= currentYearSkew;
+        }
+        if (fields[YEAR] == changeYear - 1) {
+            daysInYear -= lastYearSkew;
+        }
+        return daysInYear;
     }
 
     private int daysInYear(boolean leapYear, int month) {
@@ -1204,6 +1215,15 @@
         }
         julianSkew = ((changeYear - 2000) / 400) + julianError()
                 - ((changeYear - 2000) / 100);
+        isCached = false;
+        int dayOfYear = cal.get(DAY_OF_YEAR);
+        if (dayOfYear < julianSkew) {
+            currentYearSkew = dayOfYear;
+            lastYearSkew = julianSkew - dayOfYear;
+        } else {
+            lastYearSkew = 0;
+            currentYearSkew = julianSkew;
+        }
         isCached = false;
     }
 

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=494772&r1=494771&r2=494772
==============================================================================
--- 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 01:06:41 2007
@@ -296,6 +296,16 @@
 				.getActualMaximum(Calendar.HOUR));
 		assertEquals("Wrong actual maximum value for DAY_OF_WEEK_IN_MONTH", 4, gc6
 				.getActualMaximum(Calendar.DAY_OF_WEEK_IN_MONTH));
+        
+        
+        // Regression test for harmony 2954
+        Date date = new Date(Date.parse("Jan 15 00:00:01 GMT 2000"));
+        GregorianCalendar gc = new GregorianCalendar();
+        gc.setTimeInMillis(Date.parse("Dec 15 00:00:01 GMT 1582"));
+        assertEquals(355, gc.getActualMaximum(Calendar.DAY_OF_YEAR)); 
+        gc.setGregorianChange(date);
+        gc.setTimeInMillis(Date.parse("Jan 16 00:00:01 GMT 2000"));
+        assertEquals(353, gc.getActualMaximum(Calendar.DAY_OF_YEAR)); 
 	}
 
 	/**



Mime
View raw message