@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
27 lines (26 loc) • 1.48 kB
TypeScript
/**
* Split a Unix epoch interval at arbitrary `points`, producing consecutive sub-intervals.
*
* - `points` need not be sorted — they are sorted internally before splitting.
* - Points outside `[start, end]` are dropped; they cannot introduce a boundary that isn't
* inside the interval.
* - Points exactly on `start` or `end` are dropped too — they would only produce a
* zero-length sub-interval at the edge.
* - Duplicate points collapse to a single boundary.
* - Returns `[{ start, end }]` (the whole interval, unsplit) when no valid in-range point remains.
* - Returns `[]` when `points` is not an array, when any element is not a finite number (or
* numeric string), or on invalid input (non-finite/non-integer start/end, `start > end`).
*
* @param start Unix epoch value (seconds or milliseconds) — interval start
* @param end Unix epoch value (seconds or milliseconds) — interval end
* @param points array of Unix epoch values to split at
* @returns array of `{ start, end }` records, or `[]` on invalid input
*
* @example intervalSplitAtUnix(0, 100000, [50000]) // [{ start: 0, end: 50000 }, { start: 50000, end: 100000 }]
* @example intervalSplitAtUnix(0, 100000, []) // [{ start: 0, end: 100000 }]
* @example intervalSplitAtUnix(NaN, 100000, [50000]) // []
*/
export declare function intervalSplitAtUnix(start: number | string, end: number | string, points: Array<number | string>): Array<{
start: number;
end: number;
}>;