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

This commit is contained in:
Chas Honton 2018-07-02 20:39:24 -07:00
parent ae6a24dd43
commit f56931c176
3 changed files with 30 additions and 4 deletions

View File

@ -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>

View File

@ -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());
}

View File

@ -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"));
}
}