Skip to content

//core/io.islandtime.ranges/DateRange

DateRange

common

@Serializable(with = DateRangeIsoSerializer::class)

class DateRange(val start: Date = Date.MIN, val endInclusive: Date = Date.MAX) : DateDayProgression, Interval<Date> , ClosedRange<Date>

An inclusive range of dates.

Date.MIN and Date.MAX are used as sentinels to indicate an unbounded (i.e. infinite) start or end.

Constructors

DateRange

common

constructor(start: Date = Date.MIN, endInclusive: Date = Date.MAX)

Types

Name Summary
Companion

common


object Companion

Properties

Name Summary
endExclusive

common


open override val endExclusive: Date

The end of this interval, exclusive.
endInclusive

common


open override val endInclusive: Date

The end of this interval, inclusive.
first

common


open override val first: Date
last

common


open override val last: Date
lengthInCenturies

common


val DateRange.lengthInCenturies: Centuries

The number of whole centuries between the start and end of this range.
lengthInDays

common


val DateRange.lengthInDays: Days

The number of days between the start and end of this range. A range is inclusive, so if the start and end date are the same, the length will be one day.
lengthInDecades

common


val DateRange.lengthInDecades: Decades

The number of whole decades between the start and end of this range.
lengthInMonths

common


val DateRange.lengthInMonths: Months

The number of whole months between the start and end of this range.
lengthInWeeks

common


val DateRange.lengthInWeeks: Weeks

The number of whole weeks between the start and end of this range.
lengthInYears

common


val DateRange.lengthInYears: Years

The number of whole years between the start and end of this range.
start

common


open override val start: Date

The start of this interval, inclusive.
step

common


open override val step: Days

Functions

Name Summary
at

common


infix fun DateRange.at(zone: TimeZone): ZonedDateTimeInterval

Combines this DateRange with a TimeZone to create a ZonedDateTimeInterval between the start of the first day and the end of the last day in zone.
contains

common


open operator override fun contains(value: Date): Boolean

Checks if this interval contains value.
contains

common


fun <T> Interval<T>.contains(value: T?): Boolean

Checks if this interval contains value.
equals

common


open operator override fun equals(other: Any?): Boolean
hasBoundedEnd

common


open fun hasBoundedEnd(): Boolean

Checks if this interval's end is bounded, meaning it has a finite value.
hasBoundedStart

common


open fun hasBoundedStart(): Boolean

Checks if this interval's start is bounded, meaning it has a finite value.
hashCode

common


open override fun hashCode(): Int
hasUnboundedEnd

common


open override fun hasUnboundedEnd(): Boolean

Checks if this interval's end is unbounded. In ISO-8601 terminology, this is an "open" end.
hasUnboundedStart

common


open override fun hasUnboundedStart(): Boolean

Checks if this interval's start is unbounded. In ISO-8601 terminology, this is an "open" start.
isBounded

common


open fun isBounded(): Boolean

Checks if both the start and end of this interval are bounded, meaning it has a finite range.
isEmpty

common


open override fun isEmpty(): Boolean

Checks if this progression is empty.
isUnbounded

common


open fun isUnbounded(): Boolean

Checks if both the start and end of this interval are unbounded, meaning this is an infinite time period in both directions.
iterator

common


open operator override fun iterator(): Iterator<Date>
random

common


fun DateRange.random(): Date

Returns a random date within this range using the default random number generator.

common


fun DateRange.random(random: Random): Date

Returns a random date within this range using the supplied random number generator.
randomOrNull

common


fun DateRange.randomOrNull(): Date?

Returns a random date within this range using the default random number generator or null if the interval is empty or unbounded.

common


fun DateRange.randomOrNull(random: Random): Date?

Returns a random date within this range using the supplied random number generator or null if the interval is empty or unbounded.
reversed

common


fun DateDayProgression.reversed(): DateDayProgression

Reverses this progression such that it counts down instead of up, or vice versa.
step

common


infix fun DateDayProgression.step(step: Centuries): DateMonthProgression

Creates a progression that steps over the dates in this progression in increments of centuries.

common


infix fun DateDayProgression.step(step: Days): DateDayProgression

Creates a progression that steps over the dates in this progression in increments of days.

common


infix fun DateDayProgression.step(step: Decades): DateMonthProgression

Creates a progression that steps over the dates in this progression in increments of decades.

common


infix fun DateDayProgression.step(step: Months): DateMonthProgression

Creates a progression that steps over the dates in this progression in increments of months.

common


infix fun DateDayProgression.step(step: Weeks): DateDayProgression

Creates a progression that steps over the dates in this progression in increments of weeks.

common


infix fun DateDayProgression.step(step: Years): DateMonthProgression

Creates a progression that steps over the dates in this progression in increments of years.
toInstantIntervalAt

common


fun DateRange.toInstantIntervalAt(zone: TimeZone): InstantInterval

Converts this range to an InstantInterval between the start of the first day and the end of the last day in zone.
toPeriod

common


fun DateRange.toPeriod(): Period

Converts this range into a Period of the same length. As a range is inclusive, if the start and end date are the same, the resulting period will contain one day.
toString

common


open override fun toString(): String

Converts this range to a string in ISO-8601 extended format.