@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
42 lines • 2.88 kB
TypeScript
/**
* Return the symmetric difference of two half-open Unix intervals `[start, end)` — the values
* covered by exactly one interval.
*
* - Compares numeric Unix epoch values directly.
* - The result is every maximal run covered by exactly one interval, sorted by start — the same
* as `mergeIntervals` of `subtractIntervals(a, [b])` and `subtractIntervals(b, [a])`, and the
* same as `intervalXorAllUnix([a, b])`.
* - Every boundary is an input's own `start` or `end`; no boundary is stepped by an epoch unit.
* - Touching intervals share no value, so they join into one run (`[0, 5)` xor `[5, 10)` is
* `[0, 10)`). An empty interval (`start === end`) holds no value and changes nothing.
* - Returns `[]` when the intervals are identical.
* - Returns `[{ start, end }]` when the intervals share a start or an end, or touch.
* - Returns `[{ start, end }, { start, end }]` when they partially overlap, when one strictly
* contains the other, or when they are disjoint with a gap.
* - Returns `[]` if either interval is invalid (`start > end`).
* - Returns `[]` on invalid input: non-numeric types, empty strings, and values that are not safe
* integers (fractions, `NaN`, `±Infinity`, beyond ±(2^53 − 1)).
*
* @param aStart Unix epoch value, in the one unit all epoch arguments share — first interval start
* @param aEnd Unix epoch value, in the one unit all epoch arguments share — first interval end
* @param bStart Unix epoch value, in the one unit all epoch arguments share — second interval start
* @param bEnd Unix epoch value, in the one unit all epoch arguments share — second interval end
* @returns array of `{ start, end }` records representing the symmetric difference, or `[]` on invalid input
*
* @example intervalXorUnix(0, 1500000000, 1400000000, 1700000000) // [{ start: 0, end: 1400000000 }, { start: 1500000000, end: 1700000000 }]
* @example intervalXorUnix(0, 1700000000, 1400000000, 1500000000) // [{ start: 0, end: 1400000000 }, { start: 1500000000, end: 1700000000 }]
* @example intervalXorUnix(0, 1500000000, 1500000000, 1700000000) // [{ start: 0, end: 1700000000 }] (touching intervals join)
* @example intervalXorUnix(0, 1700000000, 0, 1700000000) // []
* @example intervalXorUnix(NaN, 1500000000, 1400000000, 1700000000) // []
* @example intervalXorUnix(0, 1, 0.5, 2) // [] (fractional epoch)
*/
export declare function intervalXorUnix(aStart: number | string, aEnd: number | string, bStart: number | string, bEnd: number | string): Array<{
/** The instant the interval begins at, as a Unix epoch number in the unit the arguments share. */
start: number;
/**
* The first instant after the interval, in the same unit as `start`. It is exclusive: the
* interval holds everything from `start` up to but not including this value. It is always later
* than `start`.
*/
end: number;
}>;