8272473: Parsing epoch seconds at a DST transition with a non-UTC parser is wrong

Reviewed-by: joehw, rriggs, iris, lancea, scolebourne
This commit is contained in:
Naoto Sato 2021-08-26 16:21:23 +00:00
parent 845e1cea8d
commit fe7d70886c
2 changed files with 14 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -354,10 +354,11 @@ final class Parsed implements TemporalAccessor {
}
private void resolveInstantFields0(ZoneId selectedZone) {
Instant instant = Instant.ofEpochSecond(fieldValues.remove(INSTANT_SECONDS));
Instant instant = Instant.ofEpochSecond(fieldValues.get(INSTANT_SECONDS));
ChronoZonedDateTime<?> zdt = chrono.zonedDateTime(instant, selectedZone);
updateCheckConflict(zdt.toLocalDate());
updateCheckConflict(INSTANT_SECONDS, SECOND_OF_DAY, (long) zdt.toLocalTime().toSecondOfDay());
updateCheckConflict(INSTANT_SECONDS, OFFSET_SECONDS, (long) zdt.getOffset().getTotalSeconds());
}
//-----------------------------------------------------------------------
@ -641,9 +642,9 @@ final class Parsed implements TemporalAccessor {
}
private void resolveInstant() {
// add instant seconds if we have date, time and zone
// add instant seconds (if not present) if we have date, time and zone
// Offset (if present) will be given priority over the zone.
if (date != null && time != null) {
if (!fieldValues.containsKey(INSTANT_SECONDS) && date != null && time != null) {
Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
if (offsetSecs != null) {
ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());