harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r772140 - /harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
Date Wed, 06 May 2009 10:40:06 GMT
Author: tellison
Date: Wed May  6 10:40:05 2009
New Revision: 772140

URL: http://svn.apache.org/viewvc?rev=772140&view=rev
Log:
Apply modified patch for HARMONY-6181 ([classlib][text] SimpleDateFormatTest.test_set2DigitYearStartLjava_util_Date
would fail)

Modified:
    harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java

Modified: harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java?rev=772140&r1=772139&r2=772140&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
Wed May  6 10:40:05 2009
@@ -265,16 +265,43 @@
          * differently than Java." We need to do a trick here to follow Java
          * spec.
          */
-        if (template.equals("y")) {
-            icuFormat.applyPattern("yy");
-            pattern = "y";
-            return;
-        }
+        String templateForICU = patternForICU(template);
         icuFormat.applyPattern(template);
         pattern = template;
     }
 
     /**
+     * Converts the Java-spec pattern into an equivalent pattern used by ICU.
+     * 
+     * @param p
+     *            the Java-spec style pattern.
+     * @return the ICU-style pattern.
+     */
+    @SuppressWarnings("nls")
+    private String patternForICU(String p) {
+        String[] subPatterns = p.split("'");
+        boolean quote = false;
+        boolean first = true;
+        StringBuilder result = new StringBuilder();
+        for (String subPattern : subPatterns) {
+            if (!quote) {
+                // replace 'y' with 'yy' for ICU to follow Java spec
+                result.append((first ? "" : "'")
+                        + subPattern.replaceAll("(?<!y)y(?!y)", "yy"));
+                quote = !quote;
+                first = false;
+            } else {
+                result.append("'" + subPattern);
+                quote = !quote;
+            }
+        }
+        if (p.endsWith("'")) {
+            result.append("'");
+        }
+        return result.toString();
+    }
+
+    /**
      * Answers a new SimpleDateFormat with the same pattern and properties as
      * this SimpleDateFormat.
      * 



Mime
View raw message