harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r554942 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/GregorianCalendar.java test/api/common/tests/api/java/util/GregorianCalendarTest.java
Date Tue, 10 Jul 2007 13:42:20 GMT
Author: tonywu
Date: Tue Jul 10 06:42:19 2007
New Revision: 554942

URL: http://svn.apache.org/viewvc?view=rev&rev=554942
Log:
Fix Harmony-4372 for backward roll operation([classlib][luni] GregorianCalendar.roll() works
incorrectly around end of year if MinimalDaysInFirstWeek is 4)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/GregorianCalendar.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/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=554942&r1=554941&r2=554942
==============================================================================
--- 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 Jul 10 06:42:19 2007
@@ -1154,15 +1154,16 @@
                 int maxWeeks = (days - 1 + mod) / 7 + 1;
                 int newWeek = mod(fields[field] - 1 + value, maxWeeks) + 1;
                 if (newWeek == maxWeeks) {
-                    if (fields[day] + (newWeek - fields[field]) * 7 > days) {
-                        set(field, 1);
+                    int addDays = (newWeek - fields[field]) * 7;
+                    if (fields[day] > addDays && fields[day] + addDays > days)
{
+                            set(field, 1);
                     } else {
-                        set(field, newWeek);
+                        set(field, newWeek - 1);
                     }
                 } else if (newWeek == 1) {
                     int week = (fields[day] - ((fields[day] - 1) / 7 * 7) - 1 + mod) / 7
+ 1;
                     if (week > 1) {
-                        set(day, 1);
+                        set(field, 1);
                     } else {
                         set(field, newWeek);
                     }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java?view=diff&rev=554942&r1=554941&r2=554942
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java
Tue Jul 10 06:42:19 2007
@@ -576,6 +576,34 @@
         assertEquals("Wrong month: " + cal.getTime(), Calendar.JANUARY, cal
                 .get(Calendar.MONTH));
         assertEquals("Wrong date: " + cal.getTime(), 7, cal.get(Calendar.DATE));
+        
+        cal.roll(Calendar.WEEK_OF_YEAR, true);
+        assertEquals("Wrong year: " + cal.getTime(), 1994, cal
+                .get(Calendar.YEAR));
+        assertEquals("Wrong month: " + cal.getTime(), Calendar.JANUARY, cal
+                .get(Calendar.MONTH));
+        assertEquals("Wrong date: " + cal.getTime(), 14, cal.get(Calendar.DATE));
+        
+        cal.roll(Calendar.WEEK_OF_YEAR, false);
+        assertEquals("Wrong year: " + cal.getTime(), 1994, cal
+                .get(Calendar.YEAR));
+        assertEquals("Wrong month: " + cal.getTime(), Calendar.JANUARY, cal
+                .get(Calendar.MONTH));
+        assertEquals("Wrong date: " + cal.getTime(), 7, cal.get(Calendar.DATE));
+        
+        cal.roll(Calendar.WEEK_OF_YEAR, false);
+        assertEquals("Wrong year: " + cal.getTime(), 1994, cal
+                .get(Calendar.YEAR));
+        assertEquals("Wrong month: " + cal.getTime(), Calendar.DECEMBER, cal
+                .get(Calendar.MONTH));
+        assertEquals("Wrong date: " + cal.getTime(), 30, cal.get(Calendar.DATE));
+        
+        cal.roll(Calendar.WEEK_OF_YEAR, false);
+        assertEquals("Wrong year: " + cal.getTime(), 1994, cal
+                .get(Calendar.YEAR));
+        assertEquals("Wrong month: " + cal.getTime(), Calendar.DECEMBER, cal
+                .get(Calendar.MONTH));
+        assertEquals("Wrong date: " + cal.getTime(), 23, cal.get(Calendar.DATE));
 	}
 
 	/**



Mime
View raw message