Skip to content

//core/io.islandtime.ranges

Package-level declarations

common

Date ranges, time intervals, and the ability to iterate over them and perform various operations.

Types

Name Summary
DateDayProgression

common


abstract class DateDayProgression : Iterable<Date>
DateMonthProgression

common


class DateMonthProgression : Iterable<Date>
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.
DateTimeInterval

common


@Serializable(with = DateTimeIntervalIsoSerializer::class)

class DateTimeInterval(val start: DateTime = UNBOUNDED.start, val endExclusive: DateTime = UNBOUNDED.endExclusive) : Interval<DateTime>


An interval between two date-times, assumed to be at the same offset from UTC.
InstantInterval

common


@Serializable(with = InstantIntervalIsoSerializer::class)

class InstantInterval(start: Instant = Instant.MIN, endExclusive: Instant = Instant.MAX) : TimePointInterval<Instant> , TimePointProgressionBuilder<Instant>


A half-open interval between two instants.
Interval

common


interface Interval<T>

A half-open or closed interval.
OffsetDateTimeInterval

common


@Serializable(with = OffsetDateTimeIntervalIsoSerializer::class)

class OffsetDateTimeInterval(start: OffsetDateTime = UNBOUNDED.start, endExclusive: OffsetDateTime = UNBOUNDED.endExclusive) : TimePointInterval<OffsetDateTime>


A half-open interval between two offset date-times based on timeline order.
TimePointInterval

common


abstract class TimePointInterval<T : TimePoint<T>> : Interval<T>

A half-open interval of time points.
TimePointNanosecondProgression

common


class TimePointNanosecondProgression<T : TimePoint<T>> : TimePointProgressionBuilder<T> , Iterable<T>
TimePointProgressionBuilder

common


interface TimePointProgressionBuilder<T : TimePoint<T>>

A time point progression builder.
TimePointSecondProgression

common


class TimePointSecondProgression<T : TimePoint<T>> : TimePointProgressionBuilder<T> , Iterable<T>
ZonedDateTimeInterval

common


@Serializable(with = ZonedDateTimeIntervalIsoSerializer::class)

class ZonedDateTimeInterval(start: ZonedDateTime = UNBOUNDED.start, endExclusive: ZonedDateTime = UNBOUNDED.endExclusive) : TimePointInterval<ZonedDateTime>


A half-open interval of zoned date-times based on timeline order.

Properties

Name Summary
lengthInCenturies

common


val DateRange.lengthInCenturies: Centuries

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

common


val DateTimeInterval.lengthInCenturies: Centuries

val OffsetDateTimeInterval.lengthInCenturies: Centuries

val ZonedDateTimeInterval.lengthInCenturies: Centuries

The number of whole centuries between the start and end of this interval.
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.

common


val DateTimeInterval.lengthInDays: Days

val OffsetDateTimeInterval.lengthInDays: Days

val ZonedDateTimeInterval.lengthInDays: Days

The number of whole days between the start and end of this interval.
lengthInDecades

common


val DateRange.lengthInDecades: Decades

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

common


val DateTimeInterval.lengthInDecades: Decades

val OffsetDateTimeInterval.lengthInDecades: Decades

val ZonedDateTimeInterval.lengthInDecades: Decades

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

common


val DateTimeInterval.lengthInHours: Hours

val TimePointInterval<*>.lengthInHours: Hours

The number of whole hours between the start and end of this interval.
lengthInMicroseconds

common


val DateTimeInterval.lengthInMicroseconds: Microseconds

val TimePointInterval<*>.lengthInMicroseconds: Microseconds

The number of whole microseconds between the start and end of this interval.
lengthInMilliseconds

common


val DateTimeInterval.lengthInMilliseconds: Milliseconds

val TimePointInterval<*>.lengthInMilliseconds: Milliseconds

The number of whole milliseconds between the start and end of this interval.
lengthInMinutes

common


val DateTimeInterval.lengthInMinutes: Minutes

val TimePointInterval<*>.lengthInMinutes: Minutes

The number of whole minutes between the start and end of this interval.
lengthInMonths

common


val DateRange.lengthInMonths: Months

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

common


val DateTimeInterval.lengthInMonths: Months

val OffsetDateTimeInterval.lengthInMonths: Months

val ZonedDateTimeInterval.lengthInMonths: Months

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

common


val DateTimeInterval.lengthInNanoseconds: Nanoseconds

val TimePointInterval<*>.lengthInNanoseconds: Nanoseconds

The number of nanoseconds between the start and end of this interval.
lengthInSeconds

common


val DateTimeInterval.lengthInSeconds: Seconds

val TimePointInterval<*>.lengthInSeconds: Seconds

The number of whole seconds between the start and end of this interval.
lengthInWeeks

common


val DateRange.lengthInWeeks: Weeks

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

common


val DateTimeInterval.lengthInWeeks: Weeks

val OffsetDateTimeInterval.lengthInWeeks: Weeks

val ZonedDateTimeInterval.lengthInWeeks: Weeks

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

common


val DateRange.lengthInYears: Years

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

common


val DateTimeInterval.lengthInYears: Years

val OffsetDateTimeInterval.lengthInYears: Years

val ZonedDateTimeInterval.lengthInYears: Years

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

Functions

Name Summary
asZonedDateTimeInterval

common


fun OffsetDateTimeInterval.asZonedDateTimeInterval(): ZonedDateTimeInterval

Converts this interval to an equivalent ZonedDateTimeInterval where both endpoints are given a fixed-offset time zone.
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.

common


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

Combines this DateTimeInterval with a TimeZone to create a ZonedDateTimeInterval where both endpoints are in zone.

common


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

Combines this InstantInterval with a TimeZone to create an equivalent ZonedDateTimeInterval where both endpoints are in zone.
contains

common


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

Checks if this interval contains value.

common


operator fun <T : TimePoint<T>> TimePointInterval<T>.contains(value: TimePoint<*>?): Boolean

Checks if this interval contains value. This will always return false if value is null.
downTo

common


infix fun <T : TimePoint<T>> T.downTo(to: T): TimePointProgressionBuilder<T>

Creates a progression of time points in descending order.

common


infix fun Date.downTo(to: Date): DateDayProgression

Creates a progression of dates in descending order.
random

common


fun DateRange.random(): Date

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

common


fun DateTimeInterval.random(): DateTime

fun InstantInterval.random(): Instant

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

common


fun OffsetDateTimeInterval.random(): OffsetDateTime

Returns a random date within this interval using the default random number generator. The offset of the start date-time will be used.

common


fun ZonedDateTimeInterval.random(): ZonedDateTime

Returns a random date within this interval using the default random number generator. The zone of the start date-time will be used.

common


fun DateRange.random(random: Random): Date

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

common


fun DateTimeInterval.random(random: Random): DateTime

fun InstantInterval.random(random: Random): Instant

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

common


fun OffsetDateTimeInterval.random(random: Random): OffsetDateTime

Returns a random date within this interval using the supplied random number generator. The offset of the start date-time will be used.

common


fun ZonedDateTimeInterval.random(random: Random): ZonedDateTime

Returns a random date within this interval using the supplied random number generator. The zone of the start date-time will be used.
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 DateTimeInterval.randomOrNull(): DateTime?

fun InstantInterval.randomOrNull(): Instant?

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

common


fun OffsetDateTimeInterval.randomOrNull(): OffsetDateTime?

Returns a random date within this interval using the default random number generator or null if the interval is empty or unbounded. The offset of the start date-time will be used.

common


fun ZonedDateTimeInterval.randomOrNull(): ZonedDateTime?

Returns a random date within this interval using the default random number generator or null if the interval is empty or unbounded. The zone of the start date-time will be used.

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.

common


fun DateTimeInterval.randomOrNull(random: Random): DateTime?

fun InstantInterval.randomOrNull(random: Random): Instant?

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

common


fun OffsetDateTimeInterval.randomOrNull(random: Random): OffsetDateTime?

Returns a random date within this interval using the supplied random number generator or null if the interval is empty or unbounded. The offset of the start date-time will be used.

common


fun ZonedDateTimeInterval.randomOrNull(random: Random): ZonedDateTime?

Returns a random date within this interval using the supplied random number generator or null if the interval is empty or unbounded. The zone of the start date-time will be used.
reversed

common


fun DateDayProgression.reversed(): DateDayProgression

fun DateMonthProgression.reversed(): DateMonthProgression

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.

common


infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Days): TimePointSecondProgression<T>

infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Hours): TimePointSecondProgression<T>

infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Microseconds): TimePointNanosecondProgression<T>

infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Milliseconds): TimePointNanosecondProgression<T>

infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Minutes): TimePointSecondProgression<T>

infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Nanoseconds): TimePointNanosecondProgression<T>

infix fun <T : TimePoint<T>> TimePointProgressionBuilder<T>.step(step: Seconds): TimePointSecondProgression<T>
toDateRange

common


fun DateTimeInterval.toDateRange(): DateRange

fun OffsetDateTimeInterval.toDateRange(): DateRange

fun ZonedDateTimeInterval.toDateRange(): DateRange

Returns this interval with the precision reduced to just the date.

common


fun String.toDateRange(): DateRange

Converts a string to a DateRange.

common


fun String.toDateRange(parser: GroupedDateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): DateRange

Converts a string to a DateRange using a specific parser.
toDateRangeAt

common


fun InstantInterval.toDateRangeAt(zone: TimeZone): DateRange

Converts this interval to the equivalent DateRange when both endpoints are in zone.
toDateTimeInterval

common


fun OffsetDateTimeInterval.toDateTimeInterval(): DateTimeInterval

fun ZonedDateTimeInterval.toDateTimeInterval(): DateTimeInterval

Returns this interval with the precision reduced to only the local date and time.

common


fun String.toDateTimeInterval(): DateTimeInterval

Converts a string to a DateTimeInterval.

common


fun String.toDateTimeInterval(parser: GroupedDateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): DateTimeInterval

Converts a string to a DateTimeInterval using a specific parser.
toDateTimeIntervalAt

common


fun InstantInterval.toDateTimeIntervalAt(zone: TimeZone): DateTimeInterval

Converts this interval to the equivalent DateTimeInterval when both endpoints are in zone.
toDuration

common


fun DateTimeInterval.toDuration(): Duration

Converts this interval to the Duration between the start and end date-time, which are assumed to be in the same time zone. In general, it's more appropriate to calculate duration using Instant or ZonedDateTime as any daylight savings rules won't be taken into account when working with DateTime directly.

common


fun TimePointInterval<*>.toDuration(): Duration

Converts this interval into a Duration of the same length.
toInstantInterval

common


fun OffsetDateTimeInterval.toInstantInterval(): InstantInterval

fun ZonedDateTimeInterval.toInstantInterval(): InstantInterval

Converts this interval to an InstantInterval.

common


fun String.toInstantInterval(): InstantInterval

Converts a string to an InstantInterval.

common


fun String.toInstantInterval(parser: GroupedDateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): InstantInterval

Converts a string to an InstantInterval using a specific parser.
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.

common


fun DateTimeInterval.toInstantIntervalAt(zone: TimeZone): InstantInterval

Converts this interval to an InstantInterval where both endpoints are in zone.
toOffsetDateTimeInterval

common


fun ZonedDateTimeInterval.toOffsetDateTimeInterval(): OffsetDateTimeInterval

Converts this interval to an OffsetDateTimeInterval.

common


fun String.toOffsetDateTimeInterval(): OffsetDateTimeInterval

Converts a string to an OffsetDateTimeInterval.

common


fun String.toOffsetDateTimeInterval(parser: GroupedDateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): OffsetDateTimeInterval

Converts a string to an OffsetDateTimeInterval using a specific parser.
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.

common


fun DateTimeInterval.toPeriod(): Period

fun OffsetDateTimeInterval.toPeriod(): Period

fun ZonedDateTimeInterval.toPeriod(): Period

Converts this interval into a Period of the same length.
toZonedDateTimeInterval

common


fun String.toZonedDateTimeInterval(): ZonedDateTimeInterval

Converts a string to a ZonedDateTimeInterval.

common


fun OffsetDateTimeInterval.toZonedDateTimeInterval(zone: TimeZone, strategy: OffsetConversionStrategy): ZonedDateTimeInterval

Converts this interval to a ZonedDateTimeInterval using the specified strategy to adjust each endpoint to a valid date, time, and offset in zone.

common


fun String.toZonedDateTimeInterval(parser: GroupedDateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): ZonedDateTimeInterval

Converts a string to a ZonedDateTimeInterval using a specific parser.
until

common


infix fun Date.until(to: Date): DateRange

Creates a DateRange containing all the days from this date up to, but not including to.

common


infix fun DateTime.until(to: DateTime): DateTimeInterval

Creates a DateTimeInterval from this date-time up to, but not including the nanosecond represented by to.

common


infix fun Instant.until(to: Instant): InstantInterval

Creates an InstantInterval from this instant up to, but not including to.

common


infix fun OffsetDateTime.until(to: OffsetDateTime): OffsetDateTimeInterval

Creates an OffsetDateTimeInterval from this date-time up to, but not including to.

common


infix fun ZonedDateTime.until(to: ZonedDateTime): ZonedDateTimeInterval

Creates a ZonedDateTimeInterval from this date-time up to, but not including to.