Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider UTC ZoneId parsing/formatting inconsistency in different Java language versions #104

Open
yuri-sergiichuk opened this issue Nov 30, 2020 · 1 comment
Labels
wontfix This will not be worked on

Comments

@yuri-sergiichuk
Copy link
Contributor

yuri-sergiichuk commented Nov 30, 2020

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.

@yuri-sergiichuk yuri-sergiichuk added the wontfix This will not be worked on label Nov 30, 2020
@yuri-sergiichuk
Copy link
Contributor Author

Two bugs related to the issue are opened in the JDK: https://bit.ly/JDK-8257667 and https://bit.ly/JDK-8257647.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant