diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt new file mode 100644 index 000000000..bd682b913 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt @@ -0,0 +1,26 @@ +package at.hannibal2.skyhanni.utils + +import java.time.Instant +import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds + +@JvmInline +value class SimpleTimeMark(val millis: Long) { + operator fun minus(other: SimpleTimeMark) = + (millis - other.millis).milliseconds + + operator fun plus(other: Duration) = + SimpleTimeMark(millis + other.inWholeMilliseconds) + + fun passedSince() = if (millis == 0L) Duration.INFINITE else now() - this + + override fun toString(): String { + if (millis == 0L) return "The Far Past" + return Instant.ofEpochMilli(millis).toString() + } + + companion object { + fun now() = SimpleTimeMark(System.currentTimeMillis()) + fun farPast() = SimpleTimeMark(0) + } +}
\ No newline at end of file |