UNPKG

@burglekitt/gmt

Version:

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

28 lines (27 loc) 1.81 kB
/** * Split a datetime interval into `n` equal-length sub-intervals. * * - Returns an array of `n` `{ start, end }` records that tile the original interval, each * record's `end` equal to the next record's `start`. * - Boundaries are computed from the total elapsed nanoseconds (via `Duration.prototype.total` * with `relativeTo` set to `start`), so the split is exact whenever the total divides evenly * by `n`, and off by at most one nanosecond otherwise. * - `n === 1` returns the original interval unchanged, as a single-element array. * - A zero-length interval (`start === end`) returns `n` identical zero-length sub-intervals. * - Returns `[]` when `n` is not a positive integer, 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 n number of equal sub-intervals to produce (positive integer) * @returns array of `n` `{ start, end }` records, or `[]` on invalid input * * @example intervalDivideEquallyDateTime("2024-01-01T00:00:00", "2024-01-04T00:00:00", 3) // [{ start: "2024-01-01T00:00:00", end: "2024-01-02T00:00:00" }, { start: "2024-01-02T00:00:00", end: "2024-01-03T00:00:00" }, { start: "2024-01-03T00:00:00", end: "2024-01-04T00:00:00" }] * @example intervalDivideEquallyDateTime("2024-01-01T00:00:00", "2024-01-04T00:00:00", 1) // [{ start: "2024-01-01T00:00:00", end: "2024-01-04T00:00:00" }] * @example intervalDivideEquallyDateTime("2024-01-01T00:00:00", "2024-01-04T00:00:00", 0) // [] * @example intervalDivideEquallyDateTime("invalid", "2024-01-04T00:00:00", 3) // [] */ export declare function intervalDivideEquallyDateTime(start: string, end: string, n: number): Array<{ start: string; end: string; }>;