commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1671989 - in /commons/proper/lang/trunk/src: changes/ main/java/org/apache/commons/lang3/time/ test/java/org/apache/commons/lang3/reflect/ test/java/org/apache/commons/lang3/time/
Date Wed, 08 Apr 2015 01:48:12 GMT
Author: chas
Date: Wed Apr  8 01:48:12 2015
New Revision: 1671989

URL: http://svn.apache.org/r1671989
Log:
revert muddled commit

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    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/reflect/FieldUtilsTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1671989&r1=1671988&r2=1671989&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Wed Apr  8 01:48:12 2015
@@ -22,7 +22,7 @@
   <body>
 
   <release version="3.5" date="tba" description="tba">
-    <action issue="LANG-1107" type="update" dev="chas">Fix parsing edge cases in FastDateParser</action>
+  
   </release>
 
   <release version="3.4" date="2014-04-06" description="Feature and bugfix release">

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=1671989&r1=1671988&r2=1671989&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
Wed Apr  8 01:48:12 2015
@@ -744,13 +744,9 @@ public class FastDateParser implements D
     /**
      * A strategy that handles a timezone field in the parsing pattern
      */
-    static class TimeZoneStrategy extends Strategy {
-        private static final String RFC_822_TIME_ZONE = "[+-]\\d{4}";
-        private static final String GMT_OPTION= "GMT[+-]\\d{1,2}:\\d{2}";
-        // see http://www.iana.org/time-zones and http://cldr.unicode.org/translation/timezones
-        static final String TZ_DATABASE= "(?:\\p{L}[\\p{L}\\p{Mc}\\p{Nd}\\p{Zs}\\p{P}&&[^-]]*-?\\p{Zs}?)*";
-        private static final String VALID_TZ = "((?iu)"+RFC_822_TIME_ZONE+"|"+GMT_OPTION+"|"+TZ_DATABASE+")";
-        
+    private static class TimeZoneStrategy extends Strategy {
+
+        private final String validTimeZoneChars;
         private final SortedMap<String, TimeZone> tzNames= new TreeMap<String, TimeZone>(String.CASE_INSENSITIVE_ORDER);
 
         /**
@@ -781,6 +777,9 @@ public class FastDateParser implements D
         TimeZoneStrategy(final Locale locale) {
             final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
             for (final String[] zone : zones) {
+                if (zone[ID].startsWith("GMT")) {
+                    continue;
+                }
                 final TimeZone tz = TimeZone.getTimeZone(zone[ID]);
                 if (!tzNames.containsKey(zone[LONG_STD])){
                     tzNames.put(zone[LONG_STD], tz);
@@ -796,7 +795,16 @@ public class FastDateParser implements D
                         tzNames.put(zone[SHORT_DST], tz);
                     }
                 }
-            }            
+            }
+
+            final StringBuilder sb= new StringBuilder();
+            sb.append("(GMT[+-]\\d{1,2}:\\d{2}").append('|');
+            sb.append("[+-]\\d{4}").append('|');
+            for(final String id : tzNames.keySet()) {
+                escapeRegex(sb, id, false).append('|');
+            }
+            sb.setCharAt(sb.length()-1, ')');
+            validTimeZoneChars= sb.toString();
         }
 
         /**
@@ -804,7 +812,7 @@ public class FastDateParser implements D
          */
         @Override
         boolean addRegex(final FastDateParser parser, final StringBuilder regex) {
-            regex.append(VALID_TZ);
+            regex.append(validTimeZoneChars);
             return true;
         }
 
@@ -817,8 +825,8 @@ public class FastDateParser implements D
             if(value.charAt(0)=='+' || value.charAt(0)=='-') {
                 tz= TimeZone.getTimeZone("GMT"+value);
             }
-            else if(value.regionMatches(true, 0, "GMT", 0, 3)) {
-                tz= TimeZone.getTimeZone(value.toUpperCase());
+            else if(value.startsWith("GMT")) {
+                tz= TimeZone.getTimeZone(value);
             }
             else {
                 tz= tzNames.get(value);

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java?rev=1671989&r1=1671988&r2=1671989&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java
Wed Apr  8 01:48:12 2015
@@ -24,8 +24,8 @@ import org.junit.Test;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 import static org.junit.Assert.*;
@@ -146,36 +146,26 @@ public class FieldUtilsTest {
         FieldUtils.getField(PublicChild.class, " ", true);
     }
 
-    private Field[] allPublicChildFields() {
-        Class<? super PublicChild> parentClass = PublicChild.class.getSuperclass();
-		final Field[] fieldsParent =  parentClass.getDeclaredFields();
-        assertArrayEquals(fieldsParent, FieldUtils.getAllFields(parentClass));
-
-		final Field[] fieldsPublicChild = PublicChild.class.getDeclaredFields();
-        return ArrayUtils.addAll(fieldsPublicChild, fieldsParent);
-    }
-
-    private Field[] allIntegerFields() {
-        final Field[] fieldsNumber = Number.class.getDeclaredFields();
-        assertArrayEquals(Number.class.getDeclaredFields(), FieldUtils.getAllFields(Number.class));
-        final Field[] fieldsInteger = Integer.class.getDeclaredFields();
-        return ArrayUtils.addAll(fieldsInteger, fieldsNumber);
-    }
-    
     @Test
     public void testGetAllFields() {
         assertArrayEquals(new Field[0], FieldUtils.getAllFields(Object.class));
-        assertArrayEquals(allIntegerFields(), FieldUtils.getAllFields(Integer.class));
-        
-        assertArrayEquals(allPublicChildFields(), FieldUtils.getAllFields(PublicChild.class));
+        final Field[] fieldsNumber = Number.class.getDeclaredFields();
+        assertArrayEquals(fieldsNumber, FieldUtils.getAllFields(Number.class));
+        final Field[] fieldsInteger = Integer.class.getDeclaredFields();
+        assertArrayEquals(ArrayUtils.addAll(fieldsInteger, fieldsNumber), FieldUtils.getAllFields(Integer.class));
+        assertEquals(5, FieldUtils.getAllFields(PublicChild.class).length);
     }
 
     @Test
     public void testGetAllFieldsList() {
-        assertEquals(Collections.emptyList(), FieldUtils.getAllFieldsList(Object.class));
-        assertEquals(Arrays.asList(allIntegerFields()), FieldUtils.getAllFieldsList(Integer.class));
-        
-        assertEquals(Arrays.asList(allPublicChildFields()), FieldUtils.getAllFieldsList(PublicChild.class));
+        assertEquals(0, FieldUtils.getAllFieldsList(Object.class).size());
+        final List<Field> fieldsNumber = Arrays.asList(Number.class.getDeclaredFields());
+        assertEquals(fieldsNumber, FieldUtils.getAllFieldsList(Number.class));
+        final List<Field> fieldsInteger = Arrays.asList(Integer.class.getDeclaredFields());
+        final List<Field> allFieldsInteger = new ArrayList<Field>(fieldsInteger);
+        allFieldsInteger.addAll(fieldsNumber);
+        assertEquals(allFieldsInteger, FieldUtils.getAllFieldsList(Integer.class));
+        assertEquals(5, FieldUtils.getAllFieldsList(PublicChild.class).size());
     }
 
     @Test

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java?rev=1671989&r1=1671988&r2=1671989&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java
Wed Apr  8 01:48:12 2015
@@ -27,6 +27,7 @@ import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -137,11 +138,13 @@ public class FastDateParserSDFTest {
     }
 
     @Test
+    @Ignore // not currently supported
     public void testLowerCase() throws Exception {
         checkParse(input.toLowerCase(locale));
     }
 
     @Test
+    @Ignore // not currently supported
     public void testLowerCasePP() throws Exception {
         checkParsePosition(input.toLowerCase(locale));
     }

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=1671989&r1=1671988&r2=1671989&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
Wed Apr  8 01:48:12 2015
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 import java.io.Serializable;
-import java.text.DateFormatSymbols;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
@@ -31,7 +30,6 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
-import java.util.regex.Pattern;
 
 import org.apache.commons.lang3.SerializationUtils;
 import org.junit.Assert;
@@ -262,21 +260,21 @@ public class FastDateParserTest {
     @Test
     public void testTzParses() throws Exception {
         // Check that all Locales can parse the time formats we use
-        for(final Locale locale : Locale.getAvailableLocales()) {
-            final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(),
locale);
-
-            for(final TimeZone tz :  new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) {
-                final Calendar cal= Calendar.getInstance(tz, locale);
-                cal.clear();
-                cal.set(Calendar.YEAR, 2000);
-                cal.set(Calendar.MONTH, 1);
-                cal.set(Calendar.DAY_OF_MONTH, 10);
-                final Date expected= cal.getTime();
+    	for(final Locale locale : Locale.getAvailableLocales()) {
+    		final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(),
locale);
 
-                final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale));
-                Assert.assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(),
expected, actual);
-            }
-        }
+    		for(final TimeZone tz :  new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) {
+    			final Calendar cal= Calendar.getInstance(tz, locale);
+    			cal.clear();
+    			cal.set(Calendar.YEAR, 2000);
+    			cal.set(Calendar.MONTH, 1);
+    			cal.set(Calendar.DAY_OF_MONTH, 10);
+    			final Date expected= cal.getTime();
+
+    			final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale));
+    			Assert.assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected,
actual);
+    		}
+    	}
     }
 
 
@@ -642,19 +640,4 @@ public class FastDateParserTest {
         }
     }
 
-    @Test
-    public void testTimeZoneStrategyPattern() {
-        Pattern tz = Pattern.compile(FastDateParser.TimeZoneStrategy.TZ_DATABASE);
-        Assert.assertFalse(tz.matcher("GMT-1234").matches());
-
-        for (Locale locale : Locale.getAvailableLocales()) {
-            final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
-            for (final String[] zone : zones) {
-                for (String zoneExpr : zone) {
-                    Assert.assertTrue(locale.getDisplayName() + ":" + zoneExpr, tz.matcher(zoneExpr).matches());
-                }
-            }
-        }
-    }
-
 }



Mime
View raw message