File tree 1 file changed +11
-2
lines changed
src/main/kotlin/ru/kontur/kinfra/commons/time 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,12 @@ public class MonotonicInstant private constructor(
27
27
return Duration .ofNanos(nanoOffset - other.nanoOffset)
28
28
}
29
29
30
+ public fun elapsedNow (): Duration {
31
+ return Duration .ofNanos(nowNanos() - nanoOffset)
32
+ }
33
+
30
34
override fun compareTo (other : MonotonicInstant ): Int {
31
- // implies that nanoOffset is monotonic
35
+ // implies that nanoOffset is monotonic, that is it cannot overflow
32
36
return nanoOffset.compareTo(other.nanoOffset)
33
37
}
34
38
@@ -49,7 +53,12 @@ public class MonotonicInstant private constructor(
49
53
private val ORIGIN_NANOS = rawNow()
50
54
51
55
public fun now (): MonotonicInstant {
52
- return MonotonicInstant (rawNow() - ORIGIN_NANOS )
56
+ return MonotonicInstant (nowNanos())
57
+ }
58
+
59
+ private fun nowNanos (): Long {
60
+ // raw value is not used for correctness of compareTo()
61
+ return rawNow() - ORIGIN_NANOS
53
62
}
54
63
55
64
private fun rawNow (): Long {
You can’t perform that action at this time.
0 commit comments