DateRange

class DateRange(start: Date, endInclusive: Date) : DateDayProgression, Interval<Date> , ClosedRange<Date>

An inclusive range of dates.

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

Constructors

DateRange
Link copied to clipboard
common
fun DateRange(start: Date = Date.MIN, endInclusive: Date = Date.MAX)

Types

Companion
Link copied to clipboard
common
object Companion

Functions

contains
Link copied to clipboard
common
open operator override fun contains(value: Date): Boolean

Checks if this interval contains value.

equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hasBoundedEnd
Link copied to clipboard
common
open fun hasBoundedEnd(): Boolean

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

hasBoundedStart
Link copied to clipboard
common
open fun hasBoundedStart(): Boolean

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

hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
hasUnboundedEnd
Link copied to clipboard
common
open override fun hasUnboundedEnd(): Boolean

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

hasUnboundedStart
Link copied to clipboard
common
open override fun hasUnboundedStart(): Boolean

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

isBounded
Link copied to clipboard
common
open fun isBounded(): Boolean

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

isEmpty
Link copied to clipboard
common
open override fun isEmpty(): Boolean

Checks if this progression is empty.

isUnbounded
Link copied to clipboard
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
Link copied to clipboard
common
open operator override fun iterator(): Iterator<Date>
toString
Link copied to clipboard
common
open override fun toString(): String

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

Properties

endExclusive
Link copied to clipboard
common
open override val endExclusive: Date

The end of this interval, exclusive.

endInclusive
Link copied to clipboard
common
open override val endInclusive: Date

The end of this interval, inclusive.

first
Link copied to clipboard
common
open override val first: Date
last
Link copied to clipboard
common
open override val last: Date
start
Link copied to clipboard
common
open override val start: Date

The start of this interval, inclusive.

step
Link copied to clipboard
common
open override val step: Days

Extensions

at
Link copied to clipboard
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.

lengthInCenturies
Link copied to clipboard
common
val DateRange.lengthInCenturies: Centuries

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

lengthInDays
Link copied to clipboard
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
Link copied to clipboard
common
val DateRange.lengthInDecades: Decades

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

lengthInMonths
Link copied to clipboard
common
val DateRange.lengthInMonths: Months

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

lengthInWeeks
Link copied to clipboard
common
val DateRange.lengthInWeeks: Weeks

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

lengthInYears
Link copied to clipboard
common
val DateRange.lengthInYears: Years

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

random
Link copied to clipboard
common
fun DateRange.random(): Date

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

fun DateRange.random(random: Random): Date

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

randomOrNull
Link copied to clipboard
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.

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.

toInstantIntervalAt
Link copied to clipboard
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
Link copied to clipboard
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.