Created
September 6, 2024 15:55
-
-
Save agebhar1/de89650362fbee1461e4a55a6257ccb9 to your computer and use it in GitHub Desktop.
ZonedDateTime.parse() returns wrong ZoneOffset around DST fall transition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.Instant; | |
import java.time.ZoneId; | |
import java.time.ZoneOffset; | |
import java.time.ZonedDateTime; | |
import java.time.temporal.ChronoUnit; | |
/* | |
* https://bugs.openjdk.java.net/browse/JDK-8066982 -- ZonedDateTime.parse() returns wrong ZoneOffset around DST fall transition | |
*/ | |
public class DaylightSavingTime { | |
public static void main(String[] args) { | |
System.out.println(System.getProperty("java.vm.version")); | |
System.out.println(System.getProperty("java.vm.vendor")); | |
assert 1 == // | |
ChronoUnit.SECONDS.between( // | |
ZonedDateTime.parse("2018-10-28T02:59:59+02:00[Europe/Berlin]"), // | |
ZonedDateTime.parse("2018-10-28T02:00:00+01:00[Europe/Berlin]")); | |
assert 1 == // | |
ChronoUnit.SECONDS.between( // | |
ZonedDateTime.parse("2019-03-31T01:59:59+01:00[Europe/Berlin]"), // | |
ZonedDateTime.parse("2019-03-31T03:00:00+02:00[Europe/Berlin]")); | |
assert ZonedDateTime.parse("2018-10-28T02:59:59+02:00[Europe/Berlin]").toInstant().getEpochSecond() + 3600 == // | |
ZonedDateTime.parse("2018-10-28T02:59:59+01:00[Europe/Berlin]").toInstant().getEpochSecond(); | |
assert ZonedDateTime.parse("2018-10-28T02:59:59+02:00[Europe/Berlin]").equals( // | |
Instant.ofEpochSecond(1540688399).atZone(ZoneId.of("Europe/Berlin"))); | |
assert !ZonedDateTime.parse("2018-10-28T02:59:59+02:00[Europe/Berlin]").equals( // | |
Instant.ofEpochSecond(1540688399).atOffset(ZoneOffset.of("+02:00"))); | |
assert ZonedDateTime.parse("2018-10-28T02:59:59+02:00[Europe/Berlin]").toInstant().equals( // | |
ZonedDateTime.parse("2018-10-28T02:59:59+02:00").toInstant()); | |
assert ZonedDateTime.parse("2018-10-28T02:59:59+02:00[Africa/Khartoum]").toInstant().equals( // | |
ZonedDateTime.parse("2018-10-28T02:59:59+02:00").toInstant()); | |
assert ZonedDateTime.parse("2018-10-28T02:59:59+01:00[Europe/Berlin]").toInstant().equals( // | |
ZonedDateTime.parse("2018-10-28T02:59:59+01:00").toInstant()); | |
assert ZonedDateTime.parse("2018-10-28T02:59:59+01:00[Europe/Berlin]").equals( // | |
Instant.ofEpochSecond(1540691999).atZone(ZoneId.of("Europe/Berlin"))); | |
assert !ZonedDateTime.parse("2018-10-28T02:59:59+01:00[Europe/Berlin]").equals( // | |
Instant.ofEpochSecond(1540691999).atOffset(ZoneOffset.of("+01:00"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment