aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/Timer.kt
blob: 6e9b4677f319a81b3c3aadb8b675c06db389b9e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package moe.nea.firmament.util

import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource

@OptIn(ExperimentalTime::class)
class Timer {
    private var mark: TimeSource.Monotonic.ValueTimeMark? = null

    fun timePassed(): Duration {
        return mark?.elapsedNow() ?: Duration.INFINITE
    }

    fun markNow() {
        mark = TimeSource.Monotonic.markNow()
    }

    fun markFarPast() {
        mark = null
    }

}