-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
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
```
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
```