UNPKG

@burglekitt/gmt

Version:

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

25 lines (24 loc) 1.64 kB
/** * Return the combined span of two UTC intervals, or null when they are disjoint. * * - Uses `Temporal.Instant.compare` for comparison (same instant semantics). * - Overlapping intervals return their merged span. * - Adjacent intervals (e.g. `aEnd === bStart`) share one instant and ARE merged. * - Returns `null` if either interval is invalid (`start > end`). * - Returns `null` on invalid input (wrong type, malformed strings, leap seconds). * * @param aStart ISO 8601 UTC datetime string for the first interval start * @param aEnd ISO 8601 UTC datetime string for the first interval end * @param bStart ISO 8601 UTC datetime string for the second interval start * @param bEnd ISO 8601 UTC datetime string for the second interval end * @returns `{ start, end }` with the merged span, or null on invalid input / disjoint intervals * * @example intervalUnionUtc("2024-01-01T00:00:00Z", "2024-06-30T23:59:59Z", "2024-04-01T00:00:00Z", "2024-12-31T23:59:59Z") // { start: "2024-01-01T00:00:00Z", end: "2024-12-31T23:59:59Z" } * @example intervalUnionUtc("2024-01-01T00:00:00Z", "2024-06-30T23:59:59Z", "2024-06-30T23:59:59Z", "2024-12-31T23:59:59Z") // { start: "2024-01-01T00:00:00Z", end: "2024-12-31T23:59:59Z" } * @example intervalUnionUtc("2024-01-01T00:00:00Z", "2024-06-30T23:59:59Z", "2024-07-01T00:00:00Z", "2024-12-31T23:59:59Z") // null * @example intervalUnionUtc("invalid", "2024-06-30T23:59:59Z", "2024-04-01T00:00:00Z", "2024-12-31T23:59:59Z") // null */ export declare function intervalUnionUtc(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; } | null;