@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
25 lines (24 loc) • 1.49 kB
TypeScript
/**
* Return the overlapping span of two Unix epoch intervals, or null when they do not overlap.
*
* - Compares numeric Unix epoch values directly.
* - 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 (non-numeric types, non-finite values).
*
* @param aStart Unix epoch value (seconds or milliseconds) — first interval start
* @param aEnd Unix epoch value (seconds or milliseconds) — first interval end
* @param bStart Unix epoch value (seconds or milliseconds) — second interval start
* @param bEnd Unix epoch value (seconds or milliseconds) — second interval end
* @returns `{ start, end }` with the overlapping span, or null on invalid input / no overlap
*
* @example intervalIntersectionUnix(0, 1700000000, 1000000, 2000000) // { start: 1000000, end: 1700000000 }
* @example intervalIntersectionUnix(0, 1000000, 1000000, 2000000) // { start: 1000000, end: 1000000 }
* @example intervalIntersectionUnix(0, 1000000, 1000001, 2000000) // null
* @example intervalIntersectionUnix(NaN, 1700000000, 1000000, 2000000) // null
* @example intervalIntersectionUnix("0", "1700000000", "1000000", "2000000") // { start: 1000000, end: 1700000000 }
*/
export declare function intervalIntersectionUnix(aStart: number | string, aEnd: number | string, bStart: number | string, bEnd: number | string): {
start: number;
end: number;
} | null;