Minor: add an "until" infix function that applies to Temporal's ... the primary purpose of this beyond a trivial bit of extra readability, is null safety.

This commit is contained in:
Mike Hearn 2016-01-07 14:57:45 +01:00
parent 2190fbf2ee
commit 5f8dec4ff9

View File

@ -14,6 +14,7 @@ import com.google.common.util.concurrent.SettableFuture
import org.slf4j.Logger
import java.security.SecureRandom
import java.time.Duration
import java.time.temporal.Temporal
import java.util.concurrent.Executor
val Int.days: Duration get() = Duration.ofDays(this.toLong())
@ -40,4 +41,7 @@ fun <T> SettableFuture<T>.setFrom(logger: Logger? = null, block: () -> T): Setta
setException(e)
}
return this
}
}
// Simple infix function to add back null safety that the JDK lacks: timeA until timeB
infix fun Temporal.until(endExclusive: Temporal) = Duration.between(this, endExclusive)