[threeten-dev] 2 digit year -> year date conversions for non-ISO calendars
Roger RIggs
Roger.Riggs at Oracle.com
Sun Sep 1 17:35:55 PDT 2013
Hi,
The behavior of the parser for 2 digit years does not work as expected
for non-ISO calendars. Due to the definition in DateTimeFormatterBuilder
of the "yy" pattern as being based on the year 2000 it only works for
The ISO and GregorianCalendars; but for the ThaiBuddhistCalendar
with the year offset and for the HijrahCalendar it produces dates that
do not resolve correctly and causes an exception.
For example,
Chronology chrono = ThaiBuddhistChronology.INSTANCE;
Locale locale = Locale.getDefault(Locale.Category.FORMAT);
String pattern = "M/d/yy G";
DateTimeFormatter df
= new DateTimeFormatterBuilder().appendPattern(pattern)
.toFormatter()
.withChronology(chrono);
ThaiBuddhistDate expected =
ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 2576, 10, 29);
String input = "10/29/76 B.E.";
parsed = df.parse(input);
ThaiBuddhistDate actual = ThaiBuddhistDate.from(parsed);
System.out.printf("pattern=%s, input=\"%s\", date=%s, TB date:
%s%n", pattern, input, parsed, actual);
The output is:
pattern=M/d/yy G, input="10/29/76 B.E.", date={},ThaiBuddhist,null
resolved to ThaiBuddhist BE 2076-10-29,null, TB date: ThaiBuddhist BE
2076-10-29
Expected: ThaiBuddhist BE 2576-10-29
Actual: ThaiBuddhist BE 2076-10-29
See JBS issue:
* JDK-8024076 <https://bugs.openjdk.java.net/browse/JDK-8024076>
Incorrect 2 -> 4 year parsing and resolution in DateTimeFormatter
Roger
More information about the threeten-dev
mailing list