diff options
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/utils')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/Timer.kt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/kotlin/com/ambientaddons/utils/Timer.kt b/src/main/kotlin/com/ambientaddons/utils/Timer.kt new file mode 100644 index 0000000..dab30b2 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/Timer.kt @@ -0,0 +1,30 @@ +package com.ambientaddons.utils + +class Timer { + private var previousTime: Long = 0 + private var startTime: Long? = null + + var isRunning: Boolean = false + private set + + private val sessionTime: Long + get() { + return startTime?.let { System.currentTimeMillis() - it } ?: 0 + } + + private val time: Long + get() { + return sessionTime?.let { it + previousTime } ?: 0 + } + + fun start() { + isRunning = true + startTime = System.currentTimeMillis() + } + + fun stop() { + isRunning = false + previousTime = sessionTime + startTime = null + } +}
\ No newline at end of file |