[threeten-dev] 2 digit year -> year date conversions for non-ISO calendars
roger riggs
roger.riggs at oracle.com
Sun Sep 8 12:13:02 PDT 2013
Hi,
The parsing of the pattern "yy" is unambiguously spec'd to parse 2 digit
years
but the DateTimeFormatterBuilder.appendValueReduced can be used for any
field type not just YEAR. So either the pattern mapping for 'yy' to
reducedValue
needs to map it to a different PrinterParser -or- the ReducedPrinterParser
can be specialized to treat the YEAR field specially. The special case
defines the baseValue to be the ISO year and it is converted to the
effective Chronology at the point that the value has been parsed and is
being
set in the Temporal.
Please review and consider the solution in the webrev.
http://cr.openjdk.java.net/~rriggs/webrev-two-digit-8024076/
Thanks, Roger
[1] http://bugs.sun.com/view_bug.do?bug_id=8024076
[2] http://cr.openjdk.java.net/~rriggs/webrev-two-digit-8024076/
On 9/1/2013 8:35 PM, Roger RIggs wrote:
> 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