UNPKG

@burglekitt/gmt

Version:

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

29 lines (28 loc) 1.86 kB
/** * Split a datetime 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, which `divideEqually`'s zero-length case is the * deliberate way to express, not `splitAt`'s. * - 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 valid ISO * PlainDateTime string, or on invalid input (unparseable start/end, `start > end`). * * @param start ISO PlainDateTime string for the interval start * @param end ISO PlainDateTime string for the interval end * @param points array of ISO PlainDateTime strings to split at * @returns array of `{ start, end }` records, or `[]` on invalid input * * @example intervalSplitAtDateTime("2024-01-01T00:00:00", "2024-01-10T00:00:00", ["2024-01-05T00:00:00"]) // [{ start: "2024-01-01T00:00:00", end: "2024-01-05T00:00:00" }, { start: "2024-01-05T00:00:00", end: "2024-01-10T00:00:00" }] * @example intervalSplitAtDateTime("2024-01-01T00:00:00", "2024-01-10T00:00:00", []) // [{ start: "2024-01-01T00:00:00", end: "2024-01-10T00:00:00" }] * @example intervalSplitAtDateTime("invalid", "2024-01-10T00:00:00", ["2024-01-05T00:00:00"]) // [] * @example intervalSplitAtDateTime("2024-01-01T00:00:00", "2024-01-10T00:00:00", ["not-a-datetime"]) // [] */ export declare function intervalSplitAtDateTime(start: string, end: string, points: string[]): Array<{ start: string; end: string; }>;