@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
25 lines (24 loc) • 1.37 kB
TypeScript
/**
* Return the portion(s) of interval A not covered by interval B.
*
* - Compares numeric Unix epoch values directly.
* - 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 (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 array of `{ start, end }` records representing A minus B, or `[]` on invalid input
*
* @example intervalDifferenceUnix(0, 1700000000, 1500000000, 1600000000) // [{ start: 0, end: 1499999999 }]
* @example intervalDifferenceUnix(0, 1700000000, 0, 1700000000) // []
* @example intervalDifferenceUnix(NaN, 1700000000, 1500000000, 1600000000) // []
*/
export declare function intervalDifferenceUnix(aStart: number | string, aEnd: number | string, bStart: number | string, bEnd: number | string): Array<{
start: number;
end: number;
}>;