aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/Timer.kt
blob: bfdc9d1299d6232f6cb627b83ccab04a2a7102be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
    }

}