@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.
32 lines • 2.33 kB
TypeScript
/**
* Return true when the half-open interval B `[bStart, bEnd)` lies within the half-open interval
* A `[aStart, aEnd)` — every clock time of B is also in A.
*
* - Half-open: an interval holds every `t` with `start <= t < end`. B may start at A's start and
* end at A's end, because neither end is part of either interval.
* - B must also overlap A, so an empty B (`bStart === bEnd`) counts only strictly inside A, never
* at an edge (CORE-6's `clampInterval` clamps it away there).
* - Equivalent to 4-argument `intervalContainsTime(aStart, aEnd, bStart, bEnd)`.
* - PlainTime has no day rollover: an interval never wraps past midnight. And because `end` is
* excluded, no interval *contains* `23:59:59.999999999` — containing it would need an `end`
* greater than it, and no PlainTime is. An interval may still *have* it as its `end`:
* `intervalContainsTime("09:00:00", "23:59:59.999999999", "23:00:00")` is `true`, while
* `intervalContainsTime("09:00:00", "23:59:59.999999999", "23:59:59.999999999")` is `false`.
* - Uses `Temporal.PlainTime.compare` for comparison.
* - Returns `false` if either interval is invalid (`start > end`).
* - Returns `false` on invalid input (wrong type, malformed strings).
*
* @param aStart ISO 8601 time string for the outer interval start
* @param aEnd ISO 8601 time string for the outer interval end (excluded)
* @param bStart ISO 8601 time string for the inner interval start
* @param bEnd ISO 8601 time string for the inner interval end (excluded)
* @returns true if B lies within A, or false on invalid input
*
* @example intervalEngulfsTime("09:00:00", "17:00:00", "12:00:00", "13:00:00") // true
* @example intervalEngulfsTime("09:00:00", "17:00:00", "09:00:00", "17:00:00") // true (equal intervals)
* @example intervalEngulfsTime("09:00:00", "17:00:00", "12:00:00", "17:00:00") // true (same end)
* @example intervalEngulfsTime("09:00:00", "17:00:00", "12:00:00", "12:00:00") // true (empty interval strictly inside)
* @example intervalEngulfsTime("09:00:00", "17:00:00", "17:00:00", "17:00:00") // false (empty interval at the edge)
* @example intervalEngulfsTime("12:00:00", "13:00:00", "09:00:00", "17:00:00") // false
*/
export declare function intervalEngulfsTime(aStart: string, aEnd: string, bStart: string, bEnd: string): boolean;