-
Notifications
You must be signed in to change notification settings - Fork 0
Description
While migrating one of the projects we've found an inconsistent behavior in parsing and formatting UTC java.time.ZoneId in different Java language versions.
As per our tests, Java 11 and Java 15 are converting UTC to Etc/UTC Zone ID while Java 8-10 and Java 12-14 are converting UTC to UTC Zone ID.
The following code snippet can be used as a minimalistic example of the issue:
final class ZonedParser {
public static void main(String[] args) {
DateTimeFormatter ZONED_FORMATTER = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm a z", Locale.US);
ZonedDateTime result = ZONED_FORMATTER.parse("05/17/2021 09:23 PM UTC", ZonedDateTime::from);
if (!result.getZone().equals(ZoneId.of("UTC"))) {
throw new IllegalStateException("Zone ID must be equal to `UTC`.");
}
}
}Running the example with different JVMs produces different results.
We've tested OpenJDK, Azul JDK, Amazon Corretto JDK and all produce similar inconsistency. A detailed OS- and JDK-specific testing matrix is available here with tests running on Windows, Linux, and macOS under JDKs from 8 to 15.
A more detailed example and explanation are available under a separate repository: https://github.com/yuri-sergiichuk/jdk-zone-parsing-inconsistency.