You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2018/07/03 03:48:24 UTC

[lang] LANG-1380: FastDateParser too strict on abbreviated short month symbols

Repository: commons-lang
Updated Branches:
  refs/heads/master ae6a24dd4 -> f56931c17


LANG-1380: FastDateParser too strict on abbreviated short month symbols


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/f56931c1
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/f56931c1
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/f56931c1

Branch: refs/heads/master
Commit: f56931c176fef5e164b681c740746aebdccccec3
Parents: ae6a24d
Author: Chas Honton <ch...@apache.org>
Authored: Mon Jul 2 20:39:24 2018 -0700
Committer: Chas Honton <ch...@apache.org>
Committed: Mon Jul 2 20:39:24 2018 -0700

----------------------------------------------------------------------
 src/changes/changes.xml                           |  3 ++-
 .../apache/commons/lang3/time/FastDateParser.java | 18 ++++++++++++++++--
 .../commons/lang3/time/FastDateParserTest.java    | 13 ++++++++++++-
 3 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/f56931c1/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4fb91b1..3701743 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
 
   <release version="3.8" date="2018-MM-DD" description="New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.">
+    <action issue="LANG-1380" type="fix" dev="chas" due-to="Markus Jelsma">FastDateParser too strict on abbreviated short month symbols</action>
     <action issue="LANG-1396" type="fix" dev="sebb">JsonToStringStyle does not escape string names</action>
     <action issue="LANG-1395" type="fix" dev="sebb" due-to="Jim Gan">JsonToStringStyle does not escape double quote in a string value</action>
     <action issue="LANG-1384" type="fix" dev="erans" due-to="Ian Young">New Java version ("11") must be handled</action>
@@ -64,7 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action issue="LANG-1391" type="add" dev="ggregory" due-to="Sauro Matulli, Oleg Chubaryov">Improve Javadoc for StringUtils.isAnyEmpty(null)</action>   
     <action issue="LANG-1393" type="add" dev="ggregory" due-to="Gary Gregory">Add API SystemUtils.String getEnvironmentVariable(final String name, final String defaultValue)</action>   
     <action issue="LANG-1394" type="add" dev="ggregory" due-to="Sebb, Gary Gregory">org.apache.commons.lang3.SystemUtils should not write to System.err.</action>   
-    <action issue="LANG-1238" type="add" dev="ggregory" due-to="Christopher Cordeiro, Gary Gregory, Bruno P. Kinoshita, Oleg Chubaryov">Add RegexUtils class instead of overloading methods in StringUtils that take a regex to take precompiled Pattern.</action>   
+    <action issue="LANG-1238" type="add" dev="ggregory" due-to="Christopher Cordeiro, Gary Gregory, Bruno P. Kinoshita, Oleg Chubaryov">Add RegexUtils class instead of overloading methods in StringUtils that take a regex to take precompiled Pattern.</action>
     <action issue="LANG-1290" type="add" dev="ggregory" due-to="Jochen Schalanda">StringUtils.join() with support for List&lt;?> with configurable start/end indices.</action>
     <action issue="LANG-1392" type="add" dev="pschumacher" due-to="Jeff Nelson">Methods for getting first non empty or non blank value</action> 
   </release>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/f56931c1/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
index 05eeb47..ed0301e 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
@@ -448,6 +448,10 @@ public class FastDateParser implements DateParser, Serializable {
                 sb.append(c);
             }
         }
+        if(sb.charAt(sb.length() - 1) == '.') {
+            // trailing '.' is optional
+            sb.append('?');
+        }
         return sb;
     }
 
@@ -713,7 +717,12 @@ public class FastDateParser implements DateParser, Serializable {
          */
         @Override
         void setCalendar(final FastDateParser parser, final Calendar cal, final String value) {
-            final Integer iVal = lKeyValues.get(value.toLowerCase(locale));
+            final String lowerCase = value.toLowerCase(locale);
+            Integer iVal = lKeyValues.get(lowerCase);
+            if(iVal == null) {
+                // match missing the optional trailing period
+                iVal = lKeyValues.get(lowerCase + '.');
+            }
             cal.set(field, iVal.intValue());
         }
     }
@@ -892,7 +901,12 @@ public class FastDateParser implements DateParser, Serializable {
             if (tz != null) {
                 cal.setTimeZone(tz);
             } else {
-                final TzInfo tzInfo = tzNames.get(timeZone.toLowerCase(locale));
+                final String lowerCase = timeZone.toLowerCase(locale);
+                TzInfo tzInfo = tzNames.get(lowerCase);
+                if (tzInfo == null) {
+                    // match missing the optional trailing period
+                    tzInfo = tzNames.get(lowerCase + '.');
+                }
                 cal.set(Calendar.DST_OFFSET, tzInfo.dstOffset);
                 cal.set(Calendar.ZONE_OFFSET, tzInfo.zone.getRawOffset());
             }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/f56931c1/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
index f9c8747..51b7e8d 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -32,7 +32,6 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
-
 import org.apache.commons.lang3.LocaleUtils;
 import org.apache.commons.lang3.SerializationUtils;
 import org.junit.Test;
@@ -717,4 +716,16 @@ public class FastDateParserTest {
         calendar.setTime(parser.parse("7"));
         assertEquals(Calendar.SUNDAY, calendar.get(Calendar.DAY_OF_WEEK));
     }
+
+    @Test
+    public void testLang1380() throws ParseException {
+        final Calendar expected = Calendar.getInstance(GMT, Locale.FRANCE);
+        expected.clear();
+        expected.set(2014, Calendar.APRIL, 14);
+
+        final DateParser fdp = getInstance("dd MMM yyyy", GMT, Locale.FRANCE);
+        assertEquals(expected.getTime(), fdp.parse("14 avril 2014"));
+        assertEquals(expected.getTime(), fdp.parse("14 avr. 2014"));
+        assertEquals(expected.getTime(), fdp.parse("14 avr 2014"));
+    }
 }