8283681: Improve ZonedDateTime offset handling

Reviewed-by: scolebourne, naoto, rriggs
This commit is contained in:
Claes Redestad 2022-03-25 22:37:55 +00:00
parent 2600f99fec
commit 7bac0a878d
5 changed files with 156 additions and 4 deletions

View file

@ -452,9 +452,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported range
*/
private static ZonedDateTime create(long epochSecond, int nanoOfSecond, ZoneId zone) {
ZoneRules rules = zone.getRules();
Instant instant = Instant.ofEpochSecond(epochSecond, nanoOfSecond); // TODO: rules should be queryable by epochSeconds
ZoneOffset offset = rules.getOffset(instant);
// nanoOfSecond is in a range that'll not affect epochSecond, validated
// by LocalDateTime.ofEpochSecond
ZoneOffset offset = zone.getOffset(epochSecond);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(epochSecond, nanoOfSecond, offset);
return new ZonedDateTime(ldt, offset, zone);
}