intervalDivideEquallyTime
Signature
Section titled “Signature”intervalDivideEquallyTime(start: string, end: string, n: number): { start: string; end: string; }[]import { intervalDivideEquallyTime } from "@northguild/gmt/plain/interval";Split a time 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. - Time units are fixed-length, so boundaries are computed to nanosecond precision — the split is exact whenever the total nanoseconds divides evenly by
n, 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 PlainTime string for the interval start |
end |
string |
ISO PlainTime 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”intervalDivideEquallyTime("09:00:00", "17:00:00", 4) // [{ start: "09:00:00", end: "11:00:00" }, { start: "11:00:00", end: "13:00:00" }, { start: "13:00:00", end: "15:00:00" }, { start: "15:00:00", end: "17:00:00" }]intervalDivideEquallyTime("09:00:00", "17:00:00", 3) // [{ start: "09:00:00", end: "11:40:00" }, { start: "11:40:00", end: "14:20:00" }, { start: "14:20:00", end: "17:00:00" }]intervalDivideEquallyTime("09:00:00", "17:00:00", 1) // [{ start: "09:00:00", end: "17:00:00" }]intervalDivideEquallyTime("09:00:00", "17:00:00", 0) // []intervalDivideEquallyTime("invalid", "17:00:00", 3) // []