Created
July 17, 2020 15:25
-
-
Save y2k/30d15c52a4d1f3723d7552af70d5d330 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kotlin.time | |
inline class Instant(val value: Duration) : Comparable<Instant> { | |
companion object { | |
val ZERO = Instant(Duration.ZERO) | |
fun fromUnixTimeSeconds(time: Long): Instant = | |
Instant(time.seconds) | |
fun fromUnixTimeMilliSeconds(time: Long): Instant = | |
Instant(time.milliseconds) | |
} | |
operator fun plus(duration: Duration): Instant = | |
Instant(value + duration) | |
operator fun minus(duration: Duration): Instant = | |
Instant(value - duration) | |
operator fun minus(duration: Instant): Duration = | |
value - duration.value | |
override operator fun compareTo(other: Instant): Int = | |
value.compareTo(other.value) | |
fun toUnixTimeSecondsLong(): Long = | |
value.inSeconds.toLong() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment