Duration

class Duration : Comparable<Duration>

A duration of time at nanosecond precision.

For many applications, working with specific units like Hours or Seconds is more efficient and plenty adequate. However, when working with larger durations at sub-second precision, overflow is a very real possibility. Duration is capable of representing fixed, nanosecond-precision durations that span the entire supported time scale, making it more suitable for these use cases.

Types

Companion
Link copied to clipboard
common
object Companion

Functions

compareTo
Link copied to clipboard
common
open operator override fun compareTo(other: Duration): Int
div
Link copied to clipboard
common
operator fun div(scalar: Int): Duration

Divides this duration by a scalar value.

equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
isNegative
Link copied to clipboard
common
fun isNegative(): Boolean

Checks if this duration is negative.

isPositive
Link copied to clipboard
common
fun isPositive(): Boolean

Checks if this duration is positive.

isZero
Link copied to clipboard
common
fun isZero(): Boolean

Checks if this duration is zero.

minus
Link copied to clipboard
common
operator fun minus(days: Days): Duration
operator fun minus(other: Duration): Duration
operator fun minus(hours: Hours): Duration
operator fun minus(microseconds: Microseconds): Duration
operator fun minus(milliseconds: Milliseconds): Duration
operator fun minus(minutes: Minutes): Duration
operator fun minus(nanoseconds: Nanoseconds): Duration
operator fun minus(seconds: Seconds): Duration
plus
Link copied to clipboard
common
operator fun plus(days: Days): Duration
operator fun plus(other: Duration): Duration
operator fun plus(hours: Hours): Duration
operator fun plus(microseconds: Microseconds): Duration
operator fun plus(milliseconds: Milliseconds): Duration
operator fun plus(minutes: Minutes): Duration
operator fun plus(nanoseconds: Nanoseconds): Duration
operator fun plus(seconds: Seconds): Duration
times
Link copied to clipboard
common
operator fun times(scalar: Int): Duration

Multiples this duration by a scalar value.

toComponents
Link copied to clipboard
common
inline fun <T> toComponents(action: (seconds: Seconds, nanoseconds: Nanoseconds) -> T): T
inline fun <T> toComponents(action: (minutes: Minutes, seconds: Seconds, nanoseconds: Nanoseconds) -> T): T
inline fun <T> toComponents(action: (hours: Hours, minutes: Minutes, seconds: Seconds, nanoseconds: Nanoseconds) -> T): T

Breaks this duration down into individual unit components.

inline fun <T> toComponents(action: (days: Days, hours: Hours, minutes: Minutes, seconds: Seconds, nanoseconds: Nanoseconds) -> T): T

Breaks this duration down into individual unit components, assuming a 24-hour day length.

toComponentValues
Link copied to clipboard
common
inline fun <T> toComponentValues(action: (seconds: Long, nanoseconds: Int) -> T): T
inline fun <T> toComponentValues(action: (minutes: Long, seconds: Int, nanoseconds: Int) -> T): T
inline fun <T> toComponentValues(action: (hours: Long, minutes: Int, seconds: Int, nanoseconds: Int) -> T): T

Breaks this duration down into individual unit components.

inline fun <T> toComponentValues(action: (days: Long, hours: Int, minutes: Int, seconds: Int, nanoseconds: Int) -> T): T

Breaks this duration down into individual unit components, assuming a 24-hour day length.

toKotlinDuration
Link copied to clipboard
common
fun toKotlinDuration(): Duration

Converts this duration to a kotlin.time.Duration. Since Kotlin's Duration type is based on a floating-point number, precision may be lost.

toString
Link copied to clipboard
common
open override fun toString(): String
truncatedTo
Link copied to clipboard
common
fun truncatedTo(unit: TimeUnit): Duration

Returns this duration, rounded down to match the precision of a given unit.

unaryMinus
Link copied to clipboard
common
operator fun unaryMinus(): Duration

Properties

absoluteValue
Link copied to clipboard
common
val absoluteValue: Duration

The absolute value of this duration.

inDays
Link copied to clipboard
common
val inDays: Days

Converts this duration into the number of 24-hour days represented by it.

inHours
Link copied to clipboard
common
val inHours: Hours

Converts this duration into the number of whole hours represented by it.

inMicroseconds
Link copied to clipboard
common
val inMicroseconds: Microseconds

Converts this duration into the number of whole microseconds represented by it.

inMilliseconds
Link copied to clipboard
common
val inMilliseconds: Milliseconds

Converts this duration into the number of whole milliseconds represented by it.

inMinutes
Link copied to clipboard
common
val inMinutes: Minutes

Converts this duration into the number of whole minutes represented by it.

inNanoseconds
Link copied to clipboard
common
val inNanoseconds: Nanoseconds

Converts this duration into Nanoseconds.

inSeconds
Link copied to clipboard
common
val inSeconds: Seconds

Returns the number of whole seconds in this duration.

nanosecondAdjustment
Link copied to clipboard
common
val nanosecondAdjustment: Nanoseconds
seconds
Link copied to clipboard
common
val seconds: Seconds

Extensions

toJavaDuration
Link copied to clipboard
fun Duration.toJavaDuration(): Duration

Converts this duration to an equivalent Java Duration.

toNSTimeInterval
Link copied to clipboard
darwin
fun Duration.toNSTimeInterval(): <ERROR CLASS>

Converts this duration to an equivalent NSTimeInterval.