Introduce ClockMark.hasPassedNow, hasNotPassedNow functions

Makes it more clear to use them than comparing elapsed with Duration.ZERO.
This commit is contained in:
Ilya Gorbunov
2019-08-15 19:12:36 +03:00
parent 44195d436e
commit a985402507
3 changed files with 40 additions and 5 deletions
+17
View File
@@ -52,6 +52,23 @@ public abstract class ClockMark {
* The returned clock mark is more _early_ when the [duration] is positive, and more _late_ when the [duration] is negative.
*/
public open operator fun minus(duration: Duration): ClockMark = plus(-duration)
/**
* Returns true if this clock mark has passed according to the clock from which this mark was taken.
*
* Note that the value returned by this function can change on subsequent invocations.
* If the clock is monotonic, it can change only from `false` to `true`, namely, when the clock mark becomes behind the current point of the clock.
*/
public fun hasPassedNow(): Boolean = !elapsedNow().isNegative()
/**
* Returns false if this clock mark has not passed according to the clock from which this mark was taken.
*
* Note that the value returned by this function can change on subsequent invocations.
* If the clock is monotonic, it can change only from `true` to `false`, namely, when the clock mark becomes behind the current point of the clock.
*/
public fun hasNotPassedNow(): Boolean = elapsedNow().isNegative()
}
@ExperimentalTime