splitIntervalByUnitTime
Signature
Section titled “Signature”splitIntervalByUnitTime(start: string, end: string, unit: string, amount: number, options?: { maxPieces?: number; }): { start: string; end: string; }[]Split a time interval into sub-intervals of amount × unit.
- Returns an array of
{ start, end }records that tile the interval, each record’sendequal to the next record’sstart. - Every piece is half-open
[start, end): a boundary belongs only to the piece that starts there, so the pieces share no value and together cover the interval exactly once (the rule CORE-6’ssplitIntervalAtuses). - The final sub-interval is trimmed so its
endnever exceeds the originalend. - Boundaries lie on the one day between
startandend:PlainTimearithmetic wraps at midnight, but a step that reaches or passes midnight is pastend, so that slice is trimmed toend("12:00"to"23:00"by 12 hours is one slice). - 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 |
Options
Section titled “Options”options
The limit on the size of the result
| Option | Type | Default | Description |
|---|---|---|---|
maxPieces? | number | 1_000_000 | The most records the result may hold. A result that would hold more, or more than the longest possible array (2^32 - 1 elements), returns [] and none is built. A value that is not a positive safe integer also returns []. |
Returns
Section titled “Returns”array of { start, end } records, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
start | string | The clock time the interval begins at, as an ISO 8601 time string with no date, offset or time zone. |
end | string | The first clock time after the interval, in the same format as start. It is exclusive: the interval holds everything from start up to but not including this value. It can equal start, which makes the interval empty. |
Examples
Section titled “Examples”import { splitIntervalByUnitTime } from "@northguild/gmt/plain/interval";
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" }]