LANG-828 FastDateParser does not handle non-Gregorian calendars properly
Fix bug in Java 7 (Locale.toString() format has changed) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1390189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
73ea9c43c6
commit
e582456625
|
@ -76,6 +76,8 @@ public class FastDateParser implements DateParser, Serializable {
|
|||
private static final ConcurrentMap<Locale,TimeZoneStrategy> tzsCache=
|
||||
new ConcurrentHashMap<Locale,TimeZoneStrategy>(3);
|
||||
|
||||
static final Locale JAPANESE_IMPERIAL = new Locale("ja","JP","JP");
|
||||
|
||||
// defining fields
|
||||
private final String pattern;
|
||||
private final TimeZone timeZone;
|
||||
|
@ -123,10 +125,12 @@ public class FastDateParser implements DateParser, Serializable {
|
|||
throw new IllegalArgumentException("Invalid pattern");
|
||||
}
|
||||
|
||||
String localeName = locale.toString();
|
||||
// These locales don't use the Gregorian calendar
|
||||
// See http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
|
||||
if (localeName.equals("ja_JP_JP") || localeName.startsWith("th_TH")) {
|
||||
// Also, the getEras() methods don't return the correct era names.
|
||||
// N.B. Not safe to use toString() comparison because that changes between Java versions
|
||||
if (locale.equals(JAPANESE_IMPERIAL)
|
||||
|| (locale.getLanguage().equals("th") && locale.getCountry().equals("TH"))) {
|
||||
collector.add(new SimpleDateFormatStrategy());
|
||||
strategies= collector.toArray(new Strategy[collector.size()]);
|
||||
parsePattern= Pattern.compile("(.*+)");
|
||||
|
|
|
@ -200,7 +200,7 @@ public class FastDateParserTest {
|
|||
Calendar cal = Calendar.getInstance(tz);
|
||||
for(int year : new int[]{2003, 1940, 1868, 1867, 0, -1940}) {
|
||||
// http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
|
||||
if (year < 1868 && locale.toString().equals("ja_JP_JP")) {
|
||||
if (year < 1868 && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
|
||||
continue; // Japanese imperial calendar does not support eras before 1868
|
||||
}
|
||||
cal.clear();
|
||||
|
@ -363,7 +363,7 @@ public class FastDateParserTest {
|
|||
boolean failed = false;
|
||||
for(Locale locale : Locale.getAvailableLocales()) {
|
||||
// ja_JP_JP cannot handle dates before 1868 properly
|
||||
if (eraBC && format.equals(SHORT_FORMAT) && locale.toString().equals("ja_JP_JP")) {
|
||||
if (eraBC && format.equals(SHORT_FORMAT) && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
|
||||
continue;
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
||||
|
|
Loading…
Reference in New Issue