diff --git a/src/share/classes/java/time/Instant.java b/src/share/classes/java/time/Instant.java index 7f7bb7ba5b66bf4a686806eb0e41bf36142d3178..42e1b8df9662f0f8587f5e6d2c77e5a62195a3ef 100644 --- a/src/share/classes/java/time/Instant.java +++ b/src/share/classes/java/time/Instant.java @@ -1058,7 +1058,8 @@ public final class Instant } // inline TemporalAccessor.super.query(query) as an optimization if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() || - query == TemporalQueries.zone() || query == TemporalQueries.offset()) { + query == TemporalQueries.zone() || query == TemporalQueries.offset() || + query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) { return null; } return query.queryFrom(this); diff --git a/src/share/classes/java/time/OffsetDateTime.java b/src/share/classes/java/time/OffsetDateTime.java index cd0eff6e56778ad4df9302d79947ffac7fd93034..4e505fcaafa92f5b0a59503566449676dec5b186 100644 --- a/src/share/classes/java/time/OffsetDateTime.java +++ b/src/share/classes/java/time/OffsetDateTime.java @@ -357,10 +357,11 @@ public final class OffsetDateTime } try { ZoneOffset offset = ZoneOffset.from(temporal); - try { - LocalDateTime ldt = LocalDateTime.from(temporal); - return OffsetDateTime.of(ldt, offset); - } catch (DateTimeException ignore) { + LocalDate date = temporal.query(TemporalQueries.localDate()); + LocalTime time = temporal.query(TemporalQueries.localTime()); + if (date != null && time != null) { + return OffsetDateTime.of(date, time, offset); + } else { Instant instant = Instant.from(temporal); return OffsetDateTime.ofInstant(instant, offset); } diff --git a/src/share/classes/java/time/ZonedDateTime.java b/src/share/classes/java/time/ZonedDateTime.java index 752756bb78b9662cfa4b408a89cb7f0227eaaa79..a23ac821d75e566fb58dabff788d0afadc4ef121 100644 --- a/src/share/classes/java/time/ZonedDateTime.java +++ b/src/share/classes/java/time/ZonedDateTime.java @@ -81,6 +81,7 @@ import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; @@ -550,14 +551,14 @@ public final class ZonedDateTime } try { ZoneId zone = ZoneId.from(temporal); - try { + if (temporal.isSupported(INSTANT_SECONDS)) { long epochSecond = temporal.getLong(INSTANT_SECONDS); int nanoOfSecond = temporal.get(NANO_OF_SECOND); return create(epochSecond, nanoOfSecond, zone); - - } catch (DateTimeException ex1) { - LocalDateTime ldt = LocalDateTime.from(temporal); - return of(ldt, zone); + } else { + LocalDate date = LocalDate.from(temporal); + LocalTime time = LocalTime.from(temporal); + return of(date, time, zone); } } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: " + @@ -2037,8 +2038,12 @@ public final class ZonedDateTime * @throws DateTimeException if unable to query (defined by the query) * @throws ArithmeticException if numeric overflow occurs (defined by the query) */ + @SuppressWarnings("unchecked") @Override // override for Javadoc public R query(TemporalQuery query) { + if (query == TemporalQueries.localDate()) { + return (R) toLocalDate(); + } return ChronoZonedDateTime.super.query(query); } diff --git a/src/share/classes/java/time/format/Parsed.java b/src/share/classes/java/time/format/Parsed.java index 5cd88e896816108e10635e936e651a1a8738847f..1eb884544140164df9857c96cff576976fa8bcc6 100644 --- a/src/share/classes/java/time/format/Parsed.java +++ b/src/share/classes/java/time/format/Parsed.java @@ -635,18 +635,20 @@ final class Parsed implements TemporalAccessor { for (Iterator> it = fieldValues.entrySet().iterator(); it.hasNext(); ) { Entry entry = it.next(); TemporalField field = entry.getKey(); - long val1; - try { - val1 = target.getLong(field); - } catch (RuntimeException ex) { - continue; - } - long val2 = entry.getValue(); - if (val1 != val2) { - throw new DateTimeException("Conflict found: Field " + field + " " + val1 + - " differs from " + field + " " + val2 + " derived from " + target); + if (target.isSupported(field)) { + long val1; + try { + val1 = target.getLong(field); + } catch (RuntimeException ex) { + continue; + } + long val2 = entry.getValue(); + if (val1 != val2) { + throw new DateTimeException("Conflict found: Field " + field + " " + val1 + + " differs from " + field + " " + val2 + " derived from " + target); + } + it.remove(); } - it.remove(); } }