< prev index next >

src/java.base/share/classes/java/time/ZonedDateTime.java

Print this page
rev 55940 : [mq]: 8211990

*** 1,7 **** /* ! * Copyright (c) 2012, 2018, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2019, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 2127,2141 **** */ @Override public long until(Temporal endExclusive, TemporalUnit unit) { ZonedDateTime end = ZonedDateTime.from(endExclusive); if (unit instanceof ChronoUnit) { end = end.withZoneSameInstant(zone); if (unit.isDateBased()) { ! return dateTime.until(end.dateTime, unit); } else { ! return toOffsetDateTime().until(end.toOffsetDateTime(), unit); } } return unit.between(this, end); } --- 2127,2147 ---- */ @Override public long until(Temporal endExclusive, TemporalUnit unit) { ZonedDateTime end = ZonedDateTime.from(endExclusive); if (unit instanceof ChronoUnit) { + ZonedDateTime start = this; + try { end = end.withZoneSameInstant(zone); + } catch (DateTimeException ex) { + // end may be out of valid range. Adjust to end's zone. + start = withZoneSameInstant(end.zone); + } if (unit.isDateBased()) { ! return start.dateTime.until(end.dateTime, unit); } else { ! return start.toOffsetDateTime().until(end.toOffsetDateTime(), unit); } } return unit.between(this, end); }
< prev index next >