TwoClocks
03/26/2021, 6:32 PMDuration
has no .between()
to get a duration between instances. which is fine... but once I include the java.time.Duration
all the nice kotlin extension functions like Int.inSeconds
can't be found. Am I just stuck w/ the java ones if I need between()
?Luke
03/26/2021, 7:34 PMTwoClocks
03/27/2021, 1:00 AMTwoClocks
03/27/2021, 1:01 AMhfhbd
03/29/2021, 7:54 AMTwoClocks
03/29/2021, 5:55 PMhfhbd
03/29/2021, 6:16 PMval upper = 5.seconds
val lower = 2.seconds
if (3.seconds in lower..upper) {
println("true 3")
}
if (1.seconds !in lower..upper) {
println("true 1")
}
rocketraman
03/29/2021, 6:36 PMimport java.time.Duration as JavaTimeDuration
.rocketraman
03/29/2021, 7:09 PMTwoClocks
03/31/2021, 4:51 PMTwoClocks
03/31/2021, 4:53 PMval start = Instant.now()
[... do something, time passes ... ]
val end = Instant.now()
val delta = Duration.between(start,end)
The kotlin duration doesn't have between()
rocketraman
03/31/2021, 4:58 PMfun ClosedRange<Instant>.duration(): Duration =
JavaTimeDuration.between(start, endInclusive).toKotlinDuration()
rocketraman
03/31/2021, 4:59 PM(start..end).duration()
rocketraman
03/31/2021, 5:04 PMDuration
, so I believe that is the best approach.rocketraman
03/31/2021, 5:09 PMval duration = measureTime { ... do something ... }
rocketraman
03/31/2021, 5:11 PMmeasureTimedValue
like this:
val (result, duration) = measureTimedValue { ... do something ... }