Time Based
A datetime unit that has the precise time duration.
Such units are independent of the time zone. Any such unit can be represented as some fixed number of nanoseconds.
See also
for a description of datetime units in general.
Samples
import kotlinx.datetime.*
import kotlin.test.*
import kotlin.time.Duration.Companion.hours
fun main() {
//sampleStart
// Constructing various time-based measurement units
val halfDay = DateTimeUnit.TimeBased(nanoseconds = 12 * 60 * 60 * 1_000_000_000L)
check(halfDay.nanoseconds == 12 * 60 * 60 * 1_000_000_000L)
check(halfDay.duration == 12.hours)
check(halfDay == DateTimeUnit.HOUR * 12)
check(halfDay == DateTimeUnit.MINUTE * 720)
check(halfDay == DateTimeUnit.SECOND * 43_200)
//sampleEnd
}
Functions
Link copied to clipboard
Produces a datetime unit that is a multiple of this unit times the specified integer scalar value.