intervalDivideEquallyDateTime
Signature
Section titled “Signature”intervalDivideEquallyDateTime(start: string, end: string, n: number): { start: string; end: string; }[]import { intervalDivideEquallyDateTime } from "@northguild/gmt/plain/interval";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’sendequal to the next record’sstart. - Boundaries are computed from the total elapsed nanoseconds (via
Duration.prototype.totalwithrelativeToset tostart), so the split is exact whenever the total divides evenly byn, and off by at most one nanosecond otherwise. n === 1returns the original interval unchanged, as a single-element array.- A zero-length interval (
start === end) returnsnidentical zero-length sub-intervals. - Returns
[]whennis not a positive integer, or on invalid input (unparseable start/end,start > end).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string |
ISO PlainDateTime string for the interval start |
end |
string |
ISO PlainDateTime string for the interval end |
n |
number |
number of equal sub-intervals to produce (positive integer) |
Returns
Section titled “Returns”array of n { start, end } records, or [] on invalid input
Examples
Section titled “Examples”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" }]intervalDivideEquallyDateTime("2024-01-01T00:00:00", "2024-01-04T00:00:00", 1) // [{ start: "2024-01-01T00:00:00", end: "2024-01-04T00:00:00" }]intervalDivideEquallyDateTime("2024-01-01T00:00:00", "2024-01-04T00:00:00", 0) // []intervalDivideEquallyDateTime("invalid", "2024-01-04T00:00:00", 3) // []