UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

25 lines (24 loc) 1.54 kB
/** * Return the portion(s) of interval A not covered by interval B. * * - Uses `Temporal.PlainDateTime.compare` for comparison. * - Returns `[]` when B fully covers A. * - Returns `[{ start, end }]` when B overlaps one edge of A (or equals A). * - Returns `[{ start, end }, { start, end }]` when B is fully inside A with gaps on both sides. * - Returns `[]` if either interval is invalid (`start > end`). * - Returns `[]` on invalid input (wrong type, malformed strings). * * @param aStart ISO 8601 datetime string for the first interval start * @param aEnd ISO 8601 datetime string for the first interval end * @param bStart ISO 8601 datetime string for the second interval start * @param bEnd ISO 8601 datetime string for the second interval end * @returns array of `{ start, end }` records representing A minus B, or `[]` on invalid input * * @example intervalDifferenceDateTime("2024-01-01T09:00:00", "2024-12-31T17:00:00", "2024-06-01T12:00:00", "2024-07-01T13:00:00") // [{ start: "2024-01-01T09:00:00", end: "2024-05-31T17:00:00" }, { start: "2024-07-01T13:00:01", end: "2024-12-31T17:00:00" }] * @example intervalDifferenceDateTime("2024-01-01T09:00:00", "2024-12-31T17:00:00", "2024-01-01T09:00:00", "2024-12-31T17:00:00") // [] * @example intervalDifferenceDateTime("invalid", "2024-12-31T17:00:00", "2024-06-01T12:00:00", "2024-07-01T13:00:00") // [] */ export declare function intervalDifferenceDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): Array<{ start: string; end: string; }>;