]> granicus.if.org Git - icu/commitdiff
ICU-7623 Merged the fix for #7595 (r27899) from trunk to maint-4-4 for ICU 4.4.1.
authorYoshito Umaoka <y.umaoka@gmail.com>
Tue, 20 Apr 2010 03:47:09 +0000 (03:47 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Tue, 20 Apr 2010 03:47:09 +0000 (03:47 +0000)
X-SVN-Rev: 27957

main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java
main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java

index 92c0e0066cd6dc77b9272b5b65265483859da15c..9f4a64d0c20b7f501de77141c63509db17210a86 100644 (file)
@@ -1605,11 +1605,17 @@ public class SimpleDateFormat extends DateFormat {
             index--;
         }
         int padding = minDigits - (limit - index);
-        for (; padding > 0; padding--) {
+        while (padding > 0 && index > 0) {
             decimalBuf[--index] = zeroDigit;
+            padding--;
         }
-        int length = limit - index;
-        buf.append(decimalBuf, index, length);
+        while (padding > 0) {
+            // when pattern width is longer than decimalBuf, need extra
+            // leading zeros - ticke#7595
+            buf.append(zeroDigit);
+            padding--;
+        }
+        buf.append(decimalBuf, index, limit - index);
     }
 
     /**
index c01152d8252654c3dc8b452d1b5559f569b77097..bd5a2e46a64ba20bf1bbec04c7eac58224aff899 100644 (file)
@@ -3676,5 +3676,29 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
             errln("DateFormat.getPatternInstance is not suppose to return an exception.");
         }
     }
-       
+
+    /*
+     * Test case for very long numeric field patterns (ticket#7595)
+     */
+    public void TestLongNumericPattern() {
+        String DATA[] = {
+            "yyyy MM dd",
+
+            "yyyy.MM.dd", "fp", "2010 04 01",
+            "2010.04.01", "2010 04 01",
+
+            "yyyyyyyyyy.MM.dd", "fp", "2010 04 01",
+            "0000002010.04.01", "2010 04 01",
+
+            "yyyyyyyyyyy.MM.dd", "fp", "2010 04 01",
+            "00000002010.04.01", "2010 04 01",
+
+            "yyyyyyyyyyy.M.dddddddddd", "fp", "2010 04 01",
+            "00000002010.4.0000000001", "2010 04 01",
+
+            "y.M.ddddddddddd", "fp", "2010 10 11",
+            "2010.10.00000000011", "2010 10 11",
+        };
+        expect(DATA, new Locale("en", "", ""));
+    }
 }