DateTimeInterval

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

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

class DateTimeInterval(start: DateTime,endExclusive: DateTime) : Interval<DateTime>

Constructors

DateTimeInterval
Link copied to clipboard
common
fun DateTimeInterval(start: DateTime, endExclusive: DateTime)

Types

Companion
Link copied to clipboard
common
object Companion

Functions

asDuration
Link copied to clipboard
common

Converts this interval to the Duration between the start and end date-time, assuming they're 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.

fun asDuration(): Duration
asPeriod
Link copied to clipboard
common

Converts this interval into a Period of the same length.

fun asPeriod(): Period
contains
Link copied to clipboard
common

Checks if this interval contains value.

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

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

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

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

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

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

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

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

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

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

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

Checks if this interval is empty.

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

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

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

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

open override fun toString(): String

Properties

endExclusive
Link copied to clipboard
common

The end of this interval, exclusive.

open override val endExclusive: DateTime
endInclusive
Link copied to clipboard
common

The end of this interval, inclusive.

open override val endInclusive: DateTime
lengthInDays
Link copied to clipboard
common

The number of whole days in this interval.

val lengthInDays: LongDays
lengthInHours
Link copied to clipboard
common

The number of whole hours in this interval.

val lengthInHours: LongHours
lengthInMicroseconds
Link copied to clipboard
common

The number of whole microseconds in this interval.

val lengthInMicroseconds: LongMicroseconds
lengthInMilliseconds
Link copied to clipboard
common

The number of whole milliseconds in this interval.

val lengthInMilliseconds: LongMilliseconds
lengthInMinutes
Link copied to clipboard
common

The number of whole minutes in this interval.

val lengthInMinutes: LongMinutes
lengthInMonths
Link copied to clipboard
common

The number of whole months in this interval.

val lengthInMonths: IntMonths
lengthInNanoseconds
Link copied to clipboard
common

The number of nanoseconds in this interval.

val lengthInNanoseconds: LongNanoseconds
lengthInSeconds
Link copied to clipboard
common

The number of whole seconds in this interval.

val lengthInSeconds: LongSeconds
lengthInWeeks
Link copied to clipboard
common

The number of whole weeks in this interval.

val lengthInWeeks: LongWeeks
lengthInYears
Link copied to clipboard
common

The number of whole years in this interval.

val lengthInYears: IntYears
start
Link copied to clipboard
common

The start of this interval, inclusive.

open override val start: DateTime

Extensions

at
Link copied to clipboard
common

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

Due to daylight savings time transitions, there a few complexities to be aware of. If the local time of either endpoint falls within a gap (meaning it doesn't exist), it will be adjusted forward by the length of the gap. If it falls within an overlap (meaning the local time exists twice), the earlier offset will be used.

infix fun DateTimeInterval.at(zone: TimeZone): ZonedDateTimeInterval
random
Link copied to clipboard
common

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

fun DateTimeInterval.random(): DateTime

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

fun DateTimeInterval.random(random: Random): DateTime
randomOrNull
Link copied to clipboard
common

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

fun DateTimeInterval.randomOrNull(): DateTime?

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

fun DateTimeInterval.randomOrNull(random: Random): DateTime?
toDateRange
Link copied to clipboard
common

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

fun DateTimeInterval.toDateRange(): DateRange
toInstantIntervalAt
Link copied to clipboard
common

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

Due to daylight savings time transitions, there a few complexities to be aware of. If the local time of either endpoint falls within a gap (meaning it doesn't exist), it will be adjusted forward by the length of the gap. If it falls within an overlap (meaning the local time exists twice), the earlier offset will be used.

fun DateTimeInterval.toInstantIntervalAt(zone: TimeZone): InstantInterval