]> granicus.if.org Git - icu/commitdiff
ICU-9242 Sync precedence table with ICU4C in the calendar code
authorMichael Ow <mow@svn.icu-project.org>
Wed, 9 May 2012 21:05:17 +0000 (21:05 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Wed, 9 May 2012 21:05:17 +0000 (21:05 +0000)
X-SVN-Rev: 31806

icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatRegressionTest.java

index ab153f5c8b142e6646bd708d0a1fdf15c6d52cc2..e4727b85adcb5bd34aad1fe5057ca4c232f3c882 100644 (file)
@@ -4817,6 +4817,8 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
             { WEEK_OF_MONTH, DOW_LOCAL },
             { DAY_OF_WEEK_IN_MONTH, DOW_LOCAL },
             { DAY_OF_YEAR },
+            { RESOLVE_REMAP | DAY_OF_MONTH, YEAR },  // if YEAR is set over YEAR_WOY use DAY_OF_MONTH
+            { RESOLVE_REMAP | WEEK_OF_YEAR, YEAR_WOY },  // if YEAR_WOY is set,  calc based on WEEK_OF_YEAR
         },
         {
             { WEEK_OF_YEAR },
@@ -4863,6 +4865,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
      */
     protected int resolveFields(int[][][] precedenceTable) {
         int bestField = -1;
+        int tempBestField;
         for (int g=0; g<precedenceTable.length && bestField < 0; ++g) {
             int[][] group = precedenceTable[g];
             int bestStamp = UNSET;
@@ -4882,8 +4885,20 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
                 }
                 // Record new maximum stamp & field no.
                 if (lineStamp > bestStamp) {
-                    bestStamp = lineStamp;
-                    bestField = line[0]; // First field refers to entire line
+                    tempBestField = line[0]; // First field refers to entire line
+                    if (tempBestField >= RESOLVE_REMAP) {
+                        tempBestField &= (RESOLVE_REMAP-1);
+                        // This check is needed to resolve some issues with UCAL_YEAR precedence mapping
+                        if (tempBestField != DATE || (stamp[WEEK_OF_MONTH] < stamp[tempBestField])) {
+                            bestField = tempBestField;
+                        }
+                    } else {
+                        bestField = tempBestField;
+                    }
+
+                    if (bestField == tempBestField) {
+                        bestStamp = lineStamp;
+                    }
                 }
             }
         }
index 5a427bc870d65d1d8747250503dfdf746324c535..8cee984bce023d9df3a52017147551097727a244 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2001-2011, International Business Machines Corporation and    *
+ * Copyright (C) 2001-2012, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -1136,4 +1136,24 @@ public class DateFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk {
             }
         }
     }
+    
+    public void TestParsing() {
+        String pattern = "EEE-WW-MMMM-yyyy";
+        String text = "mon-02-march-2011";
+        int expectedDay = 7;
+
+        SimpleDateFormat format = new SimpleDateFormat(pattern);
+        Calendar cal = GregorianCalendar.getInstance(Locale.US);
+        ParsePosition pos = new ParsePosition(0);
+        
+        try {
+            format.parse(text, cal, pos);
+        } catch (Exception e) {
+            errln("Fail parsing:  " + e);
+        }
+
+        if (cal.get(Calendar.DAY_OF_MONTH) != expectedDay) {
+            errln("Parsing failed: day of month should be '7' with pattern: \"" + pattern + "\" for text: \"" + text + "\"");
+        }
+    }
 }