UNPKG

temporal-interval

Version:

Interval class for use with Temporal Instant and PlainDateTime

61 lines (60 loc) 2.19 kB
import type { Temporal } from "@js-temporal/polyfill"; declare type Instant = Temporal.Instant; declare type PlainDateTime = Temporal.PlainDateTime; declare type ZonedDateTime = Temporal.ZonedDateTime; declare type Duration = Temporal.Duration; declare type PlainDate = Temporal.PlainDate; declare type PlainYearMonth = Temporal.PlainYearMonth; export default class Interval<T extends ZonedDateTime | Instant | PlainDateTime | PlainDate | PlainYearMonth> { private readonly _type; private readonly _compare; readonly start: T; readonly end: T; constructor(start: T, end: T | Duration); /** * Does this interval contain point b? * Assumes start is inclusive and end is exclusive */ contains(b: T): boolean; /** * Is this interval the same as another? */ equals(other: Interval<T>): boolean; /** * Does this interval fully wrap another? * Assumes start is inclusive and end is exclusive */ encloses(b: Interval<T>): boolean; /** * Does this interval overlap another? * Assumes start is inclusive and end is exclusive */ overlaps(b: Interval<T>): boolean; /** * Returns interval with the maximum start time and the minimum end time of the two intervals. */ intersection(other: Interval<T>): Interval<T> | null; /** * Returns interval with the minimum start time and the maximum end time of the two intervals. */ union(other: Interval<T>, options?: { /** throw if the intervals do not overlap or touch */ strict?: boolean; }): Interval<T> | null; /** * Generate a sequence of evenly spaced points. * The end is exclusive by default * The duration must be positive. * Warning: using durations with units more precise than the interval type * may result in an error or undefined behavior. */ iterate(duration: Temporal.DurationLike, options?: { endInclusive: boolean; }): Generator<T, void, unknown>; /** * What is the duration between the start and end? */ toDuration(options?: Parameters<T["since"]>[1]): Duration; toString(): string; } export {};