DateTimeInterval

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

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.

Constructors

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

Types

Companion
Link copied to clipboard
common
object Companion

Functions

contains
Link copied to clipboard
common
open operator override fun contains(value: DateTime): 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 interval 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.

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

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

Properties

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

The end of this interval, exclusive.

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

The end of this interval, inclusive.

start
Link copied to clipboard
common
open override val start: DateTime

The start of this interval, inclusive.

Extensions

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

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

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

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

lengthInDays
Link copied to clipboard
common
val DateTimeInterval.lengthInDays: Days

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

lengthInDecades
Link copied to clipboard
common
val DateTimeInterval.lengthInDecades: Decades

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

lengthInHours
Link copied to clipboard
common
val DateTimeInterval.lengthInHours: Hours

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

lengthInMicroseconds
Link copied to clipboard
common
val DateTimeInterval.lengthInMicroseconds: Microseconds

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

lengthInMilliseconds
Link copied to clipboard
common
val DateTimeInterval.lengthInMilliseconds: Milliseconds

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

lengthInMinutes
Link copied to clipboard
common
val DateTimeInterval.lengthInMinutes: Minutes

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

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

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

lengthInNanoseconds
Link copied to clipboard
common
val DateTimeInterval.lengthInNanoseconds: Nanoseconds

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

lengthInSeconds
Link copied to clipboard
common
val DateTimeInterval.lengthInSeconds: Seconds

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

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

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

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

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

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

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

fun DateTimeInterval.random(random: Random): DateTime

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

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

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(random: Random): DateTime?

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

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

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

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

toInstantIntervalAt
Link copied to clipboard
common
fun DateTimeInterval.toInstantIntervalAt(zone: TimeZone): InstantInterval

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

toPeriod
Link copied to clipboard
common
fun DateTimeInterval.toPeriod(): Period

Converts this interval into a Period of the same length.