LANG-1089 FastDateParser does not handle excess hours as per SimpleDateFormat

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1663348 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2015-03-02 16:29:45 +00:00
parent 6ec90c452f
commit 7c8443f66c
3 changed files with 54 additions and 7 deletions

View File

@ -22,6 +22,7 @@
<body> <body>
<release version="3.4" date="tba" description="tba"> <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-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-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> <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>

View File

@ -487,7 +487,7 @@ private Strategy getStrategy(final String formatField, final Calendar definingCa
case 'G': case 'G':
return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar); return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
case 'H': // Hour in day (0-23) 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) case 'K': // Hour in am/pm (0-11)
return HOUR_STRATEGY; return HOUR_STRATEGY;
case 'M': case 'M':
@ -501,9 +501,9 @@ private Strategy getStrategy(final String formatField, final Calendar definingCa
case 'd': case 'd':
return DAY_OF_MONTH_STRATEGY; return DAY_OF_MONTH_STRATEGY;
case 'h': // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0 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 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': case 'm':
return MINUTE_STRATEGY; return MINUTE_STRATEGY;
case 's': case 's':
@ -859,16 +859,16 @@ int modify(final int iValue) {
private static final Strategy DAY_OF_MONTH_STRATEGY = new NumberStrategy(Calendar.DAY_OF_MONTH); 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 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 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 @Override
int modify(final int iValue) { 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 @Override
int modify(final int iValue) { int modify(final int iValue) {
return iValue%12; return iValue == 12 ? 0 : iValue;
} }
}; };
private static final Strategy HOUR_STRATEGY = new NumberStrategy(Calendar.HOUR); private static final Strategy HOUR_STRATEGY = new NumberStrategy(Calendar.HOUR);

View File

@ -38,6 +38,52 @@ public static Collection<Object[]> data() {
// year tests // year tests
{ "MM/dd/yyyy", "01/11/12", Locale.UK, true}, { "MM/dd/yyyy", "01/11/12", Locale.UK, true},
{ "MM/dd/yy", "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
}); });
} }