TimeBased

class TimeBased(val nanoseconds: Long) : DateTimeUnit(source)

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
}

Constructors

Link copied to clipboard
constructor(nanoseconds: Long)

Properties

Link copied to clipboard

The length of this unit as a Duration.

Link copied to clipboard

The length of this unit in nanoseconds.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open operator override fun times(scalar: Int): DateTimeUnit.TimeBased

Produces a datetime unit that is a multiple of this unit times the specified integer scalar value.

Link copied to clipboard
open override fun toString(): String