Summary
Provide a method that returns the Duration until another Instant.
Problem
Currently, the method that returns the duration of two Instants resides in the class Duration, which may be hard for users to discover. This is based on a request from the core-libs-dev mailing list
Solution
Provide a new instance method Instant.until(Instant end) which returns a Duration from this Instant until the specified endExclusive Instant.
Specification
Add the following method in java.time.Instant class:
+ /**
+ * Calculates the {@code Duration} until another {@code Instant}.
+ * <p>
+ * The start and end points are {@code this} and the specified instant.
+ * The result will be negative if the end is before the start. Calling
+ * this method is equivalent to
+ * {@link Duration#between(Temporal, Temporal) Duration.between(this,
+ * endExclusive)}.
+ * <p>
+ * This instance is immutable and unaffected by this method call.
+ *
+ * @param endExclusive the end {@code Instant}, exclusive, not null
+ * @return the {@code Duration} from this {@code Instant} until the
+ * specified {@code endExclusive} {@code Instant}
+ * @see Duration#between(Temporal, Temporal)
+ * @since 23
+ */
+ public Duration until(Instant endExclusive)
- csr of
-
JDK-8331202 Support for Duration until another Instant
-
- Resolved
-