//core/io.islandtime.measures/Duration
Duration¶
common
@Serializable(with = DurationIsoSerializer::class)
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¶
| Name | Summary |
|---|---|
| Companion | common object Companion |
Properties¶
| Name | Summary |
|---|---|
| absoluteValue | common val absoluteValue: DurationThe absolute value of this duration. |
| inDays | common val inDays: DaysConverts this duration into the number of 24-hour days represented by it. |
| inHours | common val inHours: HoursConverts this duration into the number of whole hours represented by it. |
| inMicroseconds | common val inMicroseconds: MicrosecondsConverts this duration into the number of whole microseconds represented by it. |
| inMilliseconds | common val inMilliseconds: MillisecondsConverts this duration into the number of whole milliseconds represented by it. |
| inMinutes | common val inMinutes: MinutesConverts this duration into the number of whole minutes represented by it. |
| inNanoseconds | common val inNanoseconds: NanosecondsConverts this duration into Nanoseconds. |
| inSeconds | common val inSeconds: SecondsReturns the number of whole seconds in this duration. |
| nanosecondAdjustment | common val nanosecondAdjustment: Nanoseconds |
| seconds | common val seconds: Seconds |
Functions¶
| Name | Summary |
|---|---|
| compareTo | common open operator override fun compareTo(other: Duration): Int |
| div | common operator fun div(scalar: Int): DurationDivides this duration by a scalar value. |
| equals | common open operator override fun equals(other: Any?): Boolean |
| hashCode | common open override fun hashCode(): Int |
| isNegative | common fun isNegative(): BooleanChecks if this duration is negative. |
| isPositive | common fun isPositive(): BooleanChecks if this duration is positive. |
| isZero | common fun isZero(): BooleanChecks if this duration is zero. |
| minus | common operator fun minus(days: Days): Durationoperator fun minus(other: Duration): Durationoperator fun minus(hours: Hours): Durationoperator fun minus(microseconds: Microseconds): Durationoperator fun minus(milliseconds: Milliseconds): Durationoperator fun minus(minutes: Minutes): Durationoperator fun minus(nanoseconds: Nanoseconds): Durationoperator fun minus(seconds: Seconds): Duration |
| plus | common operator fun plus(days: Days): Durationoperator fun plus(other: Duration): Durationoperator fun plus(hours: Hours): Durationoperator fun plus(microseconds: Microseconds): Durationoperator fun plus(milliseconds: Milliseconds): Durationoperator fun plus(minutes: Minutes): Durationoperator fun plus(nanoseconds: Nanoseconds): Durationoperator fun plus(seconds: Seconds): Duration |
| times | common operator fun times(scalar: Int): DurationMultiples this duration by a scalar value. |
| toComponents | common inline fun <T> toComponents(action: (seconds: Seconds, nanoseconds: Nanoseconds) -> T): Tinline fun <T> toComponents(action: (minutes: Minutes, seconds: Seconds, nanoseconds: Nanoseconds) -> T): Tinline fun <T> toComponents(action: (hours: Hours, minutes: Minutes, seconds: Seconds, nanoseconds: Nanoseconds) -> T): TBreaks this duration down into individual unit components. common inline fun <T> toComponents(action: (days: Days, hours: Hours, minutes: Minutes, seconds: Seconds, nanoseconds: Nanoseconds) -> T): TBreaks this duration down into individual unit components, assuming a 24-hour day length. |
| toComponentValues | common inline fun <T> toComponentValues(action: (seconds: Long, nanoseconds: Int) -> T): Tinline fun <T> toComponentValues(action: (minutes: Long, seconds: Int, nanoseconds: Int) -> T): Tinline fun <T> toComponentValues(action: (hours: Long, minutes: Int, seconds: Int, nanoseconds: Int) -> T): TBreaks this duration down into individual unit components. common inline fun <T> toComponentValues(action: (days: Long, hours: Int, minutes: Int, seconds: Int, nanoseconds: Int) -> T): TBreaks this duration down into individual unit components, assuming a 24-hour day length. |
| toJavaDuration | jvm fun Duration.toJavaDuration(): DurationConverts this duration to an equivalent Java Duration. |
| toKotlinDuration | common fun toKotlinDuration(): DurationConverts this duration to a kotlin.time.Duration. Since Kotlin's Duration type can only represent longer durations to the millisecond, precision may be lost. |
| toNSTimeInterval | darwin fun Duration.toNSTimeInterval(): <Error class: unknown class>Converts this duration to an equivalent NSTimeInterval. |
| toString | common open override fun toString(): String |
| truncatedTo | common fun truncatedTo(unit: TimeUnit): DurationReturns this duration, rounded down to match the precision of a given unit. |
| unaryMinus | common operator fun unaryMinus(): Duration |