Package kotlin.time
API for representing Duration values and experimental API for measuring time intervals.
Types
ComparableTimeMark
A TimeMark that can be compared for difference with other time marks obtained from the same TimeSource.WithComparableMarks time source.
interface ComparableTimeMark :
TimeMark,
Comparable<ComparableTimeMark>
Duration
Represents the amount of time one instant of time is away from another instant.
class Duration : Comparable<Duration>
DurationUnit
The list of possible time measurement units, in which a duration can be expressed.
enum class DurationUnit
TestTimeSource
A time source that has programmatically updatable readings. It is useful as a predictable source of time in tests.
class TestTimeSource : AbstractLongTimeSource
TimedValue
Data class representing a result of executing an action, along with the duration of elapsed time interval.
data class TimedValue<T>
TimeMark
Represents a time point notched on a particular TimeSource. Remains bound to the time source it was taken from and allows querying for the duration of time elapsed from that point (see the function elapsedNow).
interface TimeMark
TimeSource
A source of time for measuring time intervals.
interface TimeSource
Annotations
ExperimentalTime
This annotation marks the experimental preview of the standard library API for measuring time and working with durations.
annotation class ExperimentalTime
Extensions for External Classes
Properties
Functions
measureTime
Executes the given function block and returns the duration of elapsed time interval.
fun measureTime(block: () -> Unit): Duration
fun TimeSource.measureTime(block: () -> Unit): Duration
fun Monotonic.measureTime(block: () -> Unit): Duration
measureTimedValue
Executes the given function block and returns an instance of TimedValue class, containing both the result of the function execution and the duration of elapsed time interval.
fun <T> measureTimedValue(block: () -> T): TimedValue<T>
Executes the given block and returns an instance of TimedValue class, containing both the result of function execution and the duration of elapsed time interval.
fun <T> TimeSource.measureTimedValue(
block: () -> T
): TimedValue<T>
fun <T> Monotonic.measureTimedValue(
block: () -> T
): TimedValue<T>
toDuration
Returns a Duration equal to this Int number of the specified unit.
fun Int.toDuration(unit: DurationUnit): Duration
Returns a Duration equal to this Long number of the specified unit.
fun Long.toDuration(unit: DurationUnit): Duration
Returns a Duration equal to this Double number of the specified unit.
fun Double.toDuration(unit: DurationUnit): Duration
toJavaDuration
Converts kotlin.time.Duration value to java.time.Duration value.
toTimeUnit
Converts this kotlin.time.DurationUnit enum value to the corresponding java.util.concurrent.TimeUnit value.
fun DurationUnit.toTimeUnit(): TimeUnit