aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/java/time/OffsetDateTime.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/classes/java/time/OffsetDateTime.java')
-rw-r--r--src/share/classes/java/time/OffsetDateTime.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/share/classes/java/time/OffsetDateTime.java b/src/share/classes/java/time/OffsetDateTime.java
index f894e53e46..410c7f3a74 100644
--- a/src/share/classes/java/time/OffsetDateTime.java
+++ b/src/share/classes/java/time/OffsetDateTime.java
@@ -1592,7 +1592,8 @@ public final class OffsetDateTime
* For example, the period in days between two date-times can be calculated
* using {@code startDateTime.until(endDateTime, DAYS)}.
* <p>
- * The {@code Temporal} passed to this method must be an {@code OffsetDateTime}.
+ * The {@code Temporal} passed to this method is converted to a
+ * {@code OffsetDateTime} using {@link #from(TemporalAccessor)}.
* If the offset differs between the two date-times, the specified
* end date-time is normalized to have the same offset as this date-time.
* <p>
@@ -1620,30 +1621,27 @@ public final class OffsetDateTime
* <p>
* If the unit is not a {@code ChronoUnit}, then the result of this method
* is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)}
- * passing {@code this} as the first argument and the input temporal as
- * the second argument.
+ * passing {@code this} as the first argument and the converted input temporal
+ * as the second argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
- * @param endDateTime the end date-time, which must be an {@code OffsetDateTime}, not null
+ * @param endExclusive the end date, exclusive, which is converted to an {@code OffsetDateTime}, not null
* @param unit the unit to measure the amount in, not null
* @return the amount of time between this date-time and the end date-time
- * @throws DateTimeException if the amount cannot be calculated
+ * @throws DateTimeException if the amount cannot be calculated, or the end
+ * temporal cannot be converted to an {@code OffsetDateTime}
* @throws UnsupportedTemporalTypeException if the unit is not supported
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long until(Temporal endDateTime, TemporalUnit unit) {
- if (endDateTime instanceof OffsetDateTime == false) {
- Objects.requireNonNull(endDateTime, "endDateTime");
- throw new DateTimeException("Unable to calculate amount as objects are of two different types");
- }
+ public long until(Temporal endExclusive, TemporalUnit unit) {
+ OffsetDateTime end = OffsetDateTime.from(endExclusive);
if (unit instanceof ChronoUnit) {
- OffsetDateTime end = (OffsetDateTime) endDateTime;
end = end.withOffsetSameInstant(offset);
return dateTime.until(end.dateTime, unit);
}
- return unit.between(this, endDateTime);
+ return unit.between(this, end);
}
/**