commonMain.jetbrains.datalore.base.datetime.Instant.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.base.datetime
//class Instant @JvmOverloads constructor(val timeSinceEpoch: Long = System.currentTimeMillis()) : Comparable {
class Instant(val timeSinceEpoch: Long) : Comparable {
fun add(duration: Duration): Instant {
return Instant(timeSinceEpoch + duration.duration)
}
fun sub(duration: Duration): Instant {
return Instant(timeSinceEpoch - duration.duration)
}
fun to(instant: Instant): Duration {
return Duration(instant.timeSinceEpoch - timeSinceEpoch)
}
override fun compareTo(other: Instant): Int {
val delta = timeSinceEpoch - other.timeSinceEpoch
return if (delta > 0) {
1
} else if (delta == 0L) {
0
} else {
-1
}
}
override fun hashCode(): Int {
return timeSinceEpoch.toInt()
}
override fun toString(): String {
return "" + timeSinceEpoch
}
override fun equals(other: Any?): Boolean {
return if (other !is Instant) false else timeSinceEpoch == other.timeSinceEpoch
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy