Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8331215

Support for Duration until another Instant

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 23
    • core-libs
    • None
    • source
    • minimal
    • Adding a new method in a final class does not introduce any backward incompatibility.
    • Java API
    • SE

      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)

            naoto Naoto Sato
            rriggs Roger Riggs
            Joe Wang, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: