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

Add an overloaded Temporal::minus method that takes another temporal

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Provide an overloaded minus method in `java.time.temporal.Temporal` interface which takes another `Temporal` argument and returns a `java.time.Duration`.

      Something like this:

      ```java
          default Duration minus(Temporal other) {
              return Duration.between(other, this);
          }
      ```

      This allows, for example, to subtract two `java.time.Instant`s and get a duration between those two:

      ```java
      var instant1 = Instant.now();
      var instant2 = instant1.plus(2, ChronoUnit.MINUTES);
      var duration = instant2.minus(instant1);
      ```

      Providing this method also empowers Kotlin users to do something like this:

      ```kotlin
      val startTime = Instant.now();
      // ...
      val durationInSeconds = (Instant.now() - startTime).seconds
      ```



            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: