aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/util/TimeMark.kt')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/TimeMark.kt23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt b/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt
new file mode 100644
index 0000000..c6b2427
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt
@@ -0,0 +1,23 @@
+package com.dulkirfabric.util
+
+import java.time.Duration
+
+data class TimeMark(val timestamp: Long) {
+ companion object {
+ fun now(): TimeMark {
+ return TimeMark(System.currentTimeMillis())
+ }
+
+ fun ago(duration: Duration): TimeMark {
+ return TimeMark(System.currentTimeMillis() - duration.toMillis())
+ }
+
+ fun farPast(): TimeMark {
+ return TimeMark(0L)
+ }
+ }
+
+ fun timePassed(): Duration {
+ return Duration.ofMillis(System.currentTimeMillis() - timestamp)
+ }
+} \ No newline at end of file