All Downloads are FREE. Search and download functionalities are using the official Maven repository.

walkmc.time.StartedTime.kt Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package walkmc.time

import com.soywiz.klock.*
import walkmc.extensions.*
import kotlin.time.*

/**
 * 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

/**
 * Redefines this started time, this is, reseting their lifetime.
 */
fun StartedTime.redefine() {
   startMillis = currentMillis
}

/**
 * Returns if the lifetime of this started time is more than the specified [timespan]
 */
operator fun StartedTime.compareTo(timespan: TimeSpan): Int = lifetime.compareTo(timespan.millisecondsLong)

/**
 * Returns if the lifetime of this started time is more than the specified [duration]
 */
operator fun StartedTime.compareTo(duration: Duration): Int = lifetime.compareTo(duration.inWholeMilliseconds)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy