intervalDivideEquallyUnix
Signature
Section titled “Signature”intervalDivideEquallyUnix(start: string | number, end: string | number, n: number, options?: { maxPieces?: number; }): { start: number; end: number; }[]Split a Unix epoch interval into n equal-length sub-intervals.
- Returns an array of
nhalf-open[start, end)records that tile the original interval: each record’sendis the next record’sstartand belongs only to that next record, so the pieces share no value and together cover[start, end)exactly once. - Each boundary is
start + round((end - start) · i / n)in integers of the arguments’ own epoch unit (there is noepochUnitoption: seconds in give seconds out, milliseconds give milliseconds), taken inbigintso no product past 2^53 loses a unit: the split is exact whenever the total divides evenly byn, and within half a unit of the exact cut otherwise (an exact half rounds up). No time zone is involved. - When
nis larger than the number of whole epoch units in the interval, some pieces are empty (theirstartequals theirend): the result always has exactlynpieces. n === 1returns the original interval unchanged, as a single-element array.- A zero-length interval (
start === end) returnsnidentical zero-length sub-intervals, each an empty[start, start)that holds no instant. - Returns
[]whennis not a positive integer, or on invalid input (start/endthat is not a safe integer or numeric string of one — fractions, empty strings and values beyond ±(2^53 − 1) are invalid — orstart > end). - Returns
[]before building any piece whennexceedsoptions.maxPiecesor the longest possible array (2^32 - 1).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | number | Unix epoch value, in the one unit all epoch arguments share — interval start |
end | string | number | Unix epoch value, in the one unit all epoch arguments share — interval end |
n | number | number of equal sub-intervals to produce (positive integer) |
Options
Section titled “Options”options
optional: the limit on the number of pieces
| 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 n { start, end } records, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
start | number | The instant the interval begins at, as a Unix epoch number in the unit the arguments share. |
end | number | The first instant after the interval, in the same unit 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 { intervalDivideEquallyUnix } from "@northguild/gmt/unix/interval";
intervalDivideEquallyUnix(0, 90000000, 3) // [{ start: 0, end: 30000000 }, { start: 30000000, end: 60000000 }, { start: 60000000, end: 90000000 }]