aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt
blob: c6b24272d5e2e4e8a3fa9063e475895325708887 (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 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)
    }
}