DayBased

A datetime unit equal to some number of calendar days.

A calendar day is not considered identical to 24 hours. Thus, a DayBased unit cannot be expressed as a multiple of some TimeBased unit.

The reason lies in time zone transitions, because of which some days can be 23 or 25 hours. For example, we say that exactly a whole day has passed between 2019-10-27T02:59 and 2019-10-28T02:59 in Berlin, even though the clocks were turned back one hour, so there are, in fact, 25 hours between the two datetimes.

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 day-based measurement units
val iteration = DateTimeUnit.DayBased(days = 14)
check(iteration.days == 14)
check(iteration == DateTimeUnit.DAY * 14)
check(iteration == DateTimeUnit.WEEK * 2) 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(days: Int)

Properties

Link copied to clipboard
val days: Int

The length of this unit in days.

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.DayBased

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