net.chestmc.common.time.StartedTime.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chest-server Show documentation
Show all versions of chest-server Show documentation
A spigot fork to kotlin structure and news.
The newest version!
package net.chestmc.common.time
import net.chestmc.common.extensions.currentMillis
import net.chestmc.common.extensions.numbers.toDate
import java.util.*
/**
* A started time is a time thats holds a start millis, representing the
* current time millis of this time starteds.
*/
interface StartedTime : Comparable {
override fun compareTo(other: StartedTime): Int = lifetime.compareTo(other.lifetime)
/**
* The started cached millis.
*/
var startMillis: Long
}
/**
* Returns the lifetime of this countdown.
*/
inline val StartedTime.lifetime: Long
get() = currentMillis - startMillis
/**
* Returns the date lifetime of this countdown.
*/
inline val StartedTime.lifetimeDate: Date
get() = lifetime.toDate()
/**
* Returns the date of this started time starteds.
*/
inline val StartedTime.startDate: Date
get() = startMillis.toDate()
/**
* Redefines this started time, this is, reseting their lifetime.
*/
fun StartedTime.redefine() {
startMillis = currentMillis
}
/**
* Returns if the lifetime of this [StartedTime] more than one second.
*/
inline val StartedTime.isMoreThanOneSecond: Boolean
get() = lifetime > 1000
/**
* Returns if the lifetime of this [StartedTime] more than one minute.
*/
inline val StartedTime.isMoreThanOneMinute: Boolean
get() = lifetime > 60000
/**
* Returns if the lifetime of this [StartedTime] is more than one hour.
*/
inline val StartedTime.isMoreThanOneHour: Boolean
get() = lifetime > 3600000
/**
* Returns if the lifetime of this [StartedTime] is more than one day.
*/
inline val StartedTime.isMoreThanOneDay: Boolean
get() = lifetime > 3600000 * 24
© 2015 - 2025 Weber Informatics LLC | Privacy Policy