@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
33 lines • 2.64 kB
TypeScript
/**
* Return true when `pointOrStart` lies in the half-open interval `[intervalStart, intervalEnd)`
* (3-arg), or when the inner interval `[innerStart, innerEnd)` lies within it (4-arg).
*
* - Half-open: an interval holds every day `t` with `start <= t < end`, so `intervalEnd` itself is
* outside (the rule CORE-6's `intervalContains` uses). An empty interval (`start === end`)
* contains no point.
* - 4-arg: the inner interval must start at or after `intervalStart`, end at or before
* `intervalEnd`, and overlap the outer interval. An empty inner interval therefore counts only
* strictly inside, never at an edge (CORE-6's `clampInterval` clamps it away there).
* - Uses `Temporal.PlainDate.compare` for comparison.
* - Returns `false` if `intervalStart > intervalEnd` (invalid outer interval).
* - Returns `false` if `innerStart > innerEnd` in 4-arg mode (invalid inner interval).
* - Returns `false` on invalid input (wrong type, malformed strings).
* - Accepts RFC 9557 calendar-annotated PlainDate strings — E5 (issue #78). Ordering is
* calendar-independent, so arguments may carry different or no calendar tags.
* - Compatibility: since 1.16.0 calendar strings are RFC 9557 (ISO digits, `[u-ca=<id>]`, canonical
* calendar ids); see `isValidCalendarDate`.
*
* @param intervalStart ISO 8601 date string for the outer interval start, optionally calendar-annotated
* @param intervalEnd ISO 8601 date string for the outer interval end (excluded), optionally calendar-annotated
* @param pointOrStart ISO 8601 date string for the point (3-arg) or inner start (4-arg), optionally calendar-annotated
* @param pointEnd optional ISO 8601 date string for the inner interval end (4-arg mode), optionally calendar-annotated
* @returns true if the point or inner interval is contained, or false on invalid input
*
* @example intervalContainsDate("2024-01-01", "2024-12-31", "2024-06-15") // true
* @example intervalContainsDate("2024-01-01", "2024-12-31", "2024-12-30") // true (last value before the end)
* @example intervalContainsDate("2024-01-01", "2024-12-31", "2024-12-31") // false (end is excluded)
* @example intervalContainsDate("2024-01-01", "2024-12-31", "2024-06-15", "2024-12-31") // true (inner shares the end)
* @example intervalContainsDate("2024-01-01", "2024-12-31", "2024-12-31", "2024-12-31") // false (empty interval at the edge)
* @example intervalContainsDate("2024-12-31", "2024-01-01", "2024-06-15") // false (reversed interval)
*/
export declare function intervalContainsDate(intervalStart: string, intervalEnd: string, pointOrStart: string, pointEnd?: string): boolean;