UNPKG

@burglekitt/gmt

Version:

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

24 lines (23 loc) 1.53 kB
/** * Return the overlapping span of two datetime intervals, or null when they do not overlap. * * - Uses `Temporal.PlainDateTime.compare` for comparison. * - Adjacent intervals (e.g. `aEnd === bStart`) share one instant and DO overlap. * - Returns `null` if either interval is invalid (`start > end`). * - Returns `null` 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 `{ start, end }` with the overlapping span, or null on invalid input / no overlap * * @example intervalIntersectionDateTime("2024-01-01T10:00:00", "2024-06-30T23:59:59", "2024-04-01T00:00:00", "2024-12-31T23:59:59") // { start: "2024-04-01T00:00:00", end: "2024-06-30T23:59:59" } * @example intervalIntersectionDateTime("2024-01-01T10:00:00", "2024-06-30T23:59:59", "2024-07-01T00:00:00", "2024-12-31T23:59:59") // null * @example intervalIntersectionDateTime("2024-01-01T10:00:00", "2024-06-30T23:59:59", "2024-07-02T00:00:00", "2024-12-31T23:59:59") // null * @example intervalIntersectionDateTime("invalid", "2024-06-30T23:59:59", "2024-04-01T00:00:00", "2024-12-31T23:59:59") // null */ export declare function intervalIntersectionDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; } | null;