You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/03/02 17:29:46 UTC

svn commit: r1663348 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/time/FastDateParser.java test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java

Author: sebb
Date: Mon Mar  2 16:29:45 2015
New Revision: 1663348

URL: http://svn.apache.org/r1663348
Log:
LANG-1089 FastDateParser does not handle excess hours as per SimpleDateFormat

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/time/FastDateParserSDFTest.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=1663348&r1=1663347&r2=1663348&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Mon Mar  2 16:29:45 2015
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.4" date="tba" description="tba">
+    <action issue="LANG-1089" type="fix" dev="sebb">FastDateParser does not handle excess hours as per SimpleDateFormat</action>
     <action issue="LANG-1061" type="fix" dev="sebb" due-to="dmeneses">FastDateParser error - timezones not handled correctly</action>
     <action issue="LANG-1087" type="fix" dev="britter" due-to="Renat Zhilkibaev">NumberUtils#createNumber() returns positive BigDecimal when negative Float is expected</action>
     <action issue="LANG-1081" type="fix" dev="britter" due-to="Jonathan Baker">DiffBuilder.append(String, Object left, Object right) does not do a left.equals(right) check</action>

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=1663348&r1=1663347&r2=1663348&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 Mon Mar  2 16:29:45 2015
@@ -487,7 +487,7 @@ public class FastDateParser implements D
         case 'G':
             return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
         case 'H':  // Hour in day (0-23)
-            return MODULO_HOUR_OF_DAY_STRATEGY;
+            return HOUR_OF_DAY_STRATEGY;
         case 'K':  // Hour in am/pm (0-11) 
             return HOUR_STRATEGY;
         case 'M':
@@ -501,9 +501,9 @@ public class FastDateParser implements D
         case 'd':
             return DAY_OF_MONTH_STRATEGY;
         case 'h':  // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
-            return MODULO_HOUR_STRATEGY;
+            return HOUR12_STRATEGY;
         case 'k':  // Hour in day (1-24), i.e. midnight is 24, not 0
-            return HOUR_OF_DAY_STRATEGY;
+            return HOUR24_OF_DAY_STRATEGY;
         case 'm':
             return MINUTE_STRATEGY;
         case 's':
@@ -859,16 +859,16 @@ public class FastDateParser implements D
     private static final Strategy DAY_OF_MONTH_STRATEGY = new NumberStrategy(Calendar.DAY_OF_MONTH);
     private static final Strategy DAY_OF_WEEK_IN_MONTH_STRATEGY = new NumberStrategy(Calendar.DAY_OF_WEEK_IN_MONTH);
     private static final Strategy HOUR_OF_DAY_STRATEGY = new NumberStrategy(Calendar.HOUR_OF_DAY);
-    private static final Strategy MODULO_HOUR_OF_DAY_STRATEGY = new NumberStrategy(Calendar.HOUR_OF_DAY) {
+    private static final Strategy HOUR24_OF_DAY_STRATEGY = new NumberStrategy(Calendar.HOUR_OF_DAY) {
         @Override
         int modify(final int iValue) {
-            return iValue%24;
+            return iValue == 24 ? 0 : iValue;
         }
     };
-    private static final Strategy MODULO_HOUR_STRATEGY = new NumberStrategy(Calendar.HOUR) {
+    private static final Strategy HOUR12_STRATEGY = new NumberStrategy(Calendar.HOUR) {
         @Override
         int modify(final int iValue) {
-            return iValue%12;
+            return iValue == 12 ? 0 : iValue;
         }
     };
     private static final Strategy HOUR_STRATEGY = new NumberStrategy(Calendar.HOUR);

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=1663348&r1=1663347&r2=1663348&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 Mon Mar  2 16:29:45 2015
@@ -38,6 +38,52 @@ public class FastDateParserSDFTest {
                 // year tests
                 { "MM/dd/yyyy", "01/11/12",  Locale.UK, true},
                 { "MM/dd/yy", "01/11/12",    Locale.UK, true},
+
+                // LANG-1089
+                { "HH", "00",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "00",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "00",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "00",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "01",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "01",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "01",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "01",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "11",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "11",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "11",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "11",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "12",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "12",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "12",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "12",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "13",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "13",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "13",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "13",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "23",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "23",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "23",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "23",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "24",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "24",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "24",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "24",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "25",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "25",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "25",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "25",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
+
+                { "HH", "48",    Locale.UK, true}, // Hour in day (0-23)
+                { "KK", "48",    Locale.UK, true}, // Hour in am/pm (0-11)
+                { "hh", "48",    Locale.UK, true}, // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
+                { "kk", "48",    Locale.UK, true}, // Hour in day (1-24), i.e. midnight is 24, not 0
                 });
     }