import type { ManipulateType } from 'dayjs'; import { Inclusivity, InclusivityString } from '../common/inclusivity.js'; import { Timestamp, TimestampInput } from '../timestamp/timestamp.js'; import { MultiDateTimeRange } from '../multi-date-time-range/multi-date-time-range.js'; import { Duration } from '@wisemen/quantity'; /** * DateTimeRange only works with [) ranges internally, except for infinities * When an exclusive date is given, this date is mapped to the next or previous inclusive date * for the upper and lower bound respectively * * As a result, empty ranges cannot be represented. * DateTimeRange uses a maximum precision of milliseconds. */ export declare class DateTimeRange { private lower; private upper; /** * @param from inclusive start of the range * @param until exclusive end of the range */ constructor(from: TimestampInput, until: TimestampInput); /** * @param from start of the range * @param until end of the range * @param inclusivity inclusivity for both ends of the range */ constructor(from: TimestampInput, until: TimestampInput, inclusivity: InclusivityString); /** * @param from start of the range * @param until end of the range * @param lowerBoundInclusivity inclusivity for the start of the range (from) * @param lowerBoundInclusivity inclusivity for the end of the range (until) */ constructor(from: TimestampInput, until: TimestampInput, lowerBoundInclusivity: Inclusivity, upperBoundInclusivity: Inclusivity); /** * An alias for `inclLower` * This returns the inclusive lower bound */ get from(): Timestamp; /** * An alias for `exclUpper` * This returns the exclusive upper bound */ get until(): Timestamp; /** * Get the inclusive lower bound of this range * This is what you intend to use most of the time */ get inclLower(): Timestamp; /** * Get the exclusive lower bound of this range * Most use cases should use `inclLower` * The exclusive lower bound is 1ms before the inclusive lower bound */ get exclLower(): Timestamp; /** * Get the inclusive upper bound of this range * Most use cases should use `exclUpper` */ get inclUpper(): Timestamp; /** * Get the exclusive upper bound of this range * This is what you intend to use most of the time * The exclusive upper bound is 1ms after inclusive upper bound */ get exclUpper(): Timestamp; /** Returns the number of whole years in the range. */ get years(): number; /** Returns the number of whole months in the range. */ get months(): number; /** Returns the number of whole weeks in the range. */ get weeks(): number; /** Returns the number of whole days in the range. */ get days(): number; /** Returns the number of whole hours in the range. */ get hours(): number; /** Returns the number of whole minutes in the range. */ get minutes(): number; /** Returns the number of whole seconds in the range. */ get seconds(): number; /** Returns the number of whole milliseconds in the range. */ get milliseconds(): number; /** * Get the duration of this DateTimeRange. * * The duration is calculated as `from.until(until)` */ get duration(): Duration; /** Checks if the given date falls within the range. */ contains(date: TimestampInput): boolean; /** Checks if the given range is entirely contained within this range */ containsRange(range: DateTimeRange): boolean; /** Returns true if the range starts after the given date. */ startsAfter(date: TimestampInput): boolean; /** Returns true if the range starts after or at the given date. */ startsAfterOrAt(date: TimestampInput): boolean; /** Returns true if the range starts before the given date. */ startsBefore(date: TimestampInput): boolean; /** Returns true if the range starts before or at the given date. */ startsBeforeOrAt(date: TimestampInput): boolean; /** Returns true if the range ends before the given date. */ endsBefore(date: TimestampInput): boolean; /** Returns true if the range ends before or at the given date. */ endsBeforeOrAt(date: TimestampInput): boolean; /** Returns true if the range ends after the given date. */ endsAfter(date: TimestampInput): boolean; /** Returns true if the range ends after or at the given date. */ endsAfterOrAt(date: TimestampInput): boolean; /** Returns true if the range overlaps with another DateTimeRange. */ overlaps(withRange: DateTimeRange): boolean; /** Returns the overlapping range with another DateTimeRange, or throws if none. */ overlap(withRange: DateTimeRange): DateTimeRange; /** Returns the portions of the range not covered by another DateTimeRange as an array. */ diff(withRange: DateTimeRange): MultiDateTimeRange; /** Checks if both ranges have the same boundaries. */ isSame(otherRange: DateTimeRange): boolean; /** returns true if both boundaries are finite */ isFinite(): boolean; /** * Returns a string representation of the range, indicating inclusivity and bounds in ISO format. * @example "(-infinity, 2025-10-17T14:22:14.768+00)" */ toString(): string; toJSON(): string; /** Returns a new DateTimeRange with updated end boundary. */ withUntil(until: TimestampInput): DateTimeRange; /** Returns a new DateTimeRange with updated start boundary. */ withFrom(from: TimestampInput): DateTimeRange; /** * Returns a new date time range with both boundaries expanded \ * - from = this.from.subtractDuration(duration) * - until = this.until.addDuration(duration) */ expand(duration: Duration): DateTimeRange; /** * Returns a new date time range with both boundaries expanded \ * - from = this.from.subtractDuration(lower) * - until = this.until.addDuration(upper) */ expand(lower: Duration, upper: Duration): DateTimeRange; /** Returns true if this range ends before the other range starts */ isStrictlyBefore(other: DateTimeRange): boolean; /** Returns true if this range starts after the other range ends */ isStrictlyAfter(other: DateTimeRange): boolean; /** Returns true if this range ends immediately before the other range starts. */ precedes(other: DateTimeRange): boolean; /** Returns true if this range is immediately preceded by the other range. */ isPrecededBy(other: DateTimeRange): boolean; /** Returns true if this range starts immediately after the other range ends. */ succeeds(other: DateTimeRange): boolean; /** Returns true if this range is immediately succeeded by the other range. */ isSucceededBy(other: DateTimeRange): boolean; /** Returns true if the ranges are directly adjacent (preceding or succeeding). */ isAdjacentTo(other: DateTimeRange): boolean; /** * Compares the order (in time) of the given range with this range. \ * returns < 0 if this range is before the given range \ * returns 0 if this range is the same as the given range \ * returns > 0 if this range is after the given range \ * \ * The order is determined by first comparing the `from` of both ranges. * If `from` is the same for both ranges, `until` is compared. \ * \ * The returned value is the result of a `diff` milliseconds between the compared values. */ compare(other: DateTimeRange): number; /** * Merges two overlapping or adjacent ranges into a new range which consists of the * earliest timestamp until the latest timestamp of both ranges * @throws when ranges do not overlap */ merge(withOther: DateTimeRange): DateTimeRange; /** Merges two adjacent ranges into one; throws if not adjacent. */ mergeAdjacent(withOther: DateTimeRange): DateTimeRange; /** * Creates an iterable for every timestamp in this range starting from the start timestamp * until the end timestamp (exclusive). * * By default every day is generated (amount = 1, interval = 'day'). \ * Increasing the interval between generated timestamps will always return the start timestamp of this range * even if the next value lies beyond this range. */ iterate(amount?: number, interval?: ManipulateType): Iterable; }