Skip to main content

TimeRange

classpond-tssource

A time interval event key with inclusive start and end boundaries.

new TimeRange({ start, end })

Constructor

new TimeRange(input: TimeRangeInput)
new TimeRange([start, end])

Creates an interval key from a { start, end } object or tuple.

Properties

endMsnumberreadonly
kind'timeRange'readonly
startnumberreadonly

Static methods

fromCalendarstatic

fromCalendar(unit: CalendarUnit, reference: string, options?: CalendarOptions): TimeRange
TimeRange.fromCalendar("week", "2025-01-01", { timeZone: "UTC", weekStartsOn: 1 })

Creates the containing calendar range for the supplied reference.

fromDatestatic

fromDate(reference: string, options?: TimeZoneOptions): TimeRange
TimeRange.fromDate("2025-01-01", { timeZone: "Europe/Madrid" })

Creates the local calendar-day range for the supplied ISO date.

Methods

begin

begin(): number
range.begin()

Returns the inclusive start of the range in milliseconds since epoch.

compare

compare(other: EventKey): number
range.compare(otherRange)

Compares this key to another key for ordering.

contains

contains(other: TemporalLike): boolean
range.contains(otherRange)

Returns true when this range fully contains the supplied temporal value.

duration

duration(): number
range.duration()

Returns the temporal duration of the range in milliseconds.

end

end(): number
range.end()

Returns the inclusive end of the range in milliseconds since epoch.

equals

equals(other: EventKey): boolean
range.equals(otherRange)

Returns true when the supplied key is the same TimeRange.

intersection

intersection(other: TemporalLike): TimeRange | undefined
range.intersection(otherRange)

Returns the overlapping portion of this range and the supplied temporal value, if any.

isAfter

isAfter(other: TemporalLike): boolean
range.isAfter(otherRange)

Returns true when this range begins strictly after the supplied temporal value ends.

isBefore

isBefore(other: TemporalLike): boolean
range.isBefore(otherRange)

Returns true when this range ends strictly before the supplied temporal value begins.

midpoint

midpoint(): number
range.midpoint()

Returns the midpoint of the range in milliseconds since epoch.

overlaps

overlaps(other: TemporalLike): boolean
range.overlaps(otherRange)

Returns true when this range overlaps the supplied temporal value.

timeRange

timeRange(): TimeRange
range.timeRange()

Returns this key as a TimeRange.

toJSON

toJSON(): { end: number; start: number }
range.toJSON()

Returns { start, end } as ms-since-epoch numbers — the same shape JsonTimeRangeInput accepts, so the result round-trips through new TimeRange(range.toJSON()) and JSON wire formats. Implicitly invoked by JSON.stringify(range).

toString

toString(): string
range.toString()

Returns an ISO-8601 representation of the range as start/end, e.g. 2025-01-15T09:00:00.000Z/2025-01-15T10:00:00.000Z. Useful for debug logs and human-readable display.

trim

trim(other: TemporalLike): TimeRange | undefined
range.trim(otherRange)

Returns this range clipped to the supplied temporal value, if the two overlap.

type

type(): 'timeRange'
range.type() // "timeRange"

Returns the key kind.