java 9 AKST timezone parsing

Clément Guillaume clement at guillaume.bzh
Wed Oct 11 02:37:30 UTC 2017


Hello,

When parsing a date time string that contains a time zone like AKST, AKDT,
HST or AST with a DateTimeFormatter built from a pattern containing 'z',
java 9 returns the SystemV variant of those timezone, which then behave
differently as the "modern" ones. Looks like it's also an issue with long
time zone ("Alaska Standard Time")

>From my digging I noticed that the PrefixTree generated
by ZoneTextPrinterParser.getTree is different in java 8 and java 9, and
this may be caused by a different order in the content returned
by TimeZoneNameUtility.getZoneStrings(Locale.getDefault())

Is this an expected behavior of java 9? (other american time zones are
parsed to the modern version: PST -> America/Los_Angeles)

I tested it with java 9 build 9+181 and java 8 build 1.8.0_131-b11 (both
linux 64 with en_US as local) on this code:

import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public class Main{

public static void main(String[] args){
DateTimeFormatter timezoneFormatter = DateTimeFormatter.ofPattern("z");
TemporalAccessor temporalAccessor = timezoneFormatter.parse("AKST");
System.out.println(temporalAccessor);
temporalAccessor = timezoneFormatter.parse("AKDT");
System.out.println(temporalAccessor);
temporalAccessor = timezoneFormatter.parse("HST");
System.out.println(temporalAccessor);
temporalAccessor = timezoneFormatter.parse("AST");
System.out.println(temporalAccessor);

DateTimeFormatter isoFormatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mmX").withZone(ZoneOffset.UTC);
temporalAccessor =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSz").parse("2017-09-13T06:30:33.123AKST");
System.out.println(temporalAccessor);
System.out.println(isoFormatter.format(temporalAccessor));
temporalAccessor =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSVV").parse("2017-09-13T06:30:33.123America/Anchorage");
System.out.println(temporalAccessor);
System.out.println(isoFormatter.format(temporalAccessor));
}

}


More information about the jdk9-dev mailing list