splitIntervalByUnitTime
Signature
Section titled “Signature”splitIntervalByUnitTime(start: string, end: string, unit: string, amount: number): { start: string; end: string; }[]import { splitIntervalByUnitTime } from "@northguild/gmt/plain/interval";Split a time interval into sub-intervals of amount × unit.
- Returns an array of
{ start, end }records that tile the interval. - The final sub-interval is trimmed so its
endnever exceeds the originalend. - Returns
[{ start, end }]whenstart === end(zero-length interval). - Returns
[]on invalid input (unparseable start/end, unsupported unit, non-positive amount, or a unit that has no effect onPlainTime, e.g."days").
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 |
unit |
string |
duration unit string — "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds" (calendar units are ignored by PlainTime and return []) |
amount |
number |
positive number of units per step |
Returns
Section titled “Returns”array of { start, end } records, or [] on invalid input
Examples
Section titled “Examples”splitIntervalByUnitTime("12:00:00", "14:00:00", "hour", 1) // [{ start: "12:00:00", end: "13:00:00" }, { start: "13:00:00", end: "14:00:00" }]splitIntervalByUnitTime("12:00:00", "14:30:00", "hour", 1) // [{ start: "12:00:00", end: "13:00:00" }, { start: "13:00:00", end: "14:00:00" }, { start: "14:00:00", end: "14:30:00" }]splitIntervalByUnitTime("12:00:00", "12:00:00", "hour", 1) // [{ start: "12:00:00", end: "12:00:00" }]splitIntervalByUnitTime("12:00:00", "14:00:00", "hour", 0) // []splitIntervalByUnitTime("invalid", "14:00:00", "hour", 1) // []