commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1390189 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/time/FastDateParser.java test/java/org/apache/commons/lang3/time/FastDateParserTest.java
Date Tue, 25 Sep 2012 22:12:14 GMT
Author: sebb
Date: Tue Sep 25 22:12:14 2012
New Revision: 1390189

URL: http://svn.apache.org/viewvc?rev=1390189&view=rev
Log:
LANG-828 FastDateParser does not handle non-Gregorian calendars properly
Fix bug in Java 7 (Locale.toString() format has changed)

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java?rev=1390189&r1=1390188&r2=1390189&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
Tue Sep 25 22:12:14 2012
@@ -75,7 +75,9 @@ public class FastDateParser implements D
     
     private static final ConcurrentMap<Locale,TimeZoneStrategy> tzsCache= 
         new ConcurrentHashMap<Locale,TimeZoneStrategy>(3);
-    
+
+    static final Locale JAPANESE_IMPERIAL = new Locale("ja","JP","JP");
+
     // defining fields
     private final String pattern;
     private final TimeZone timeZone;
@@ -123,10 +125,12 @@ public class FastDateParser implements D
             throw new IllegalArgumentException("Invalid pattern");
         }
 
-        String localeName = locale.toString();
         // These locales don't use the Gregorian calendar
         // See http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
-        if (localeName.equals("ja_JP_JP") || localeName.startsWith("th_TH")) {
+        // Also, the getEras() methods don't return the correct era names.
+        // N.B. Not safe to use toString() comparison because that changes between Java versions
+        if (locale.equals(JAPANESE_IMPERIAL)
+        || (locale.getLanguage().equals("th") && locale.getCountry().equals("TH")))
{
             collector.add(new SimpleDateFormatStrategy());
             strategies= collector.toArray(new Strategy[collector.size()]);
             parsePattern= Pattern.compile("(.*+)");

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java?rev=1390189&r1=1390188&r2=1390189&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
Tue Sep 25 22:12:14 2012
@@ -200,7 +200,7 @@ public class FastDateParserTest {
                 Calendar cal = Calendar.getInstance(tz);
                 for(int year : new int[]{2003, 1940, 1868, 1867, 0, -1940}) {
                     // http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
-                    if (year < 1868 && locale.toString().equals("ja_JP_JP")) {
+                    if (year < 1868 && locale.equals(FastDateParser.JAPANESE_IMPERIAL))
{
                         continue; // Japanese imperial calendar does not support eras before
1868
                     }
                     cal.clear();
@@ -363,7 +363,7 @@ public class FastDateParserTest {
         boolean failed = false;
         for(Locale locale : Locale.getAvailableLocales()) {
             // ja_JP_JP cannot handle dates before 1868 properly
-            if (eraBC && format.equals(SHORT_FORMAT) && locale.toString().equals("ja_JP_JP"))
{
+            if (eraBC && format.equals(SHORT_FORMAT) && locale.equals(FastDateParser.JAPANESE_IMPERIAL))
{
                 continue;
             }
             SimpleDateFormat sdf = new SimpleDateFormat(format, locale);



Mime
View raw message