intervalDivideEquallyDate
Signature
Section titled “Signature”intervalDivideEquallyDate(start: string, end: string, n: number): { start: string; end: string; }[]import { intervalDivideEquallyDate } from "@northguild/gmt/plain/interval";Split a date 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. PlainDatehas no fractional-day representation, so each internal boundary is rounded to the nearest whole day — whentotalDaysisn’t evenly divisible byn, the resulting sub-intervals differ by at most one day rather than being mathematically exact.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). - Accepts GMT calendar-annotated PlainDate strings — E5 (issue #78).
startandendmust carry the same calendar tag (or both be bare ISO); a mismatch returns[](E5 decision of record D4). Internal boundaries are computed in whole days (calendar-independent), then re-formatted in the shared calendar.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string |
ISO PlainDate string for the interval start, optionally calendar-annotated |
end |
string |
ISO PlainDate string for the interval end, optionally calendar-annotated |
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 / mismatched calendars
Examples
Section titled “Examples”intervalDivideEquallyDate("2024-01-01", "2024-01-05", 4) // [{ start: "2024-01-01", end: "2024-01-02" }, { start: "2024-01-02", end: "2024-01-03" }, { start: "2024-01-03", end: "2024-01-04" }, { start: "2024-01-04", end: "2024-01-05" }]intervalDivideEquallyDate("2024-01-01", "2024-01-10", 3) // [{ start: "2024-01-01", end: "2024-01-04" }, { start: "2024-01-04", end: "2024-01-07" }, { start: "2024-01-07", end: "2024-01-10" }]intervalDivideEquallyDate("2024-01-01", "2024-01-10", 1) // [{ start: "2024-01-01", end: "2024-01-10" }]intervalDivideEquallyDate("2024-01-01", "2024-01-01", 3) // [{ start: "2024-01-01", end: "2024-01-01" }, { start: "2024-01-01", end: "2024-01-01" }, { start: "2024-01-01", end: "2024-01-01" }]intervalDivideEquallyDate("2024-01-01", "2024-01-10", 0) // []intervalDivideEquallyDate("invalid", "2024-01-10", 3) // []