mapDatesInRange
Signature
Section titled “Signature”mapDatesInRange(startDate: string, endDate: string, stepDays?: number, options?: { maxPieces?: number; }): string[]Return an array of ISO PlainDate strings between startDate and endDate inclusive.
- Generates dates with optional step (default 1 day).
- Returns [] if start > end, invalid inputs, or step <= 0.
- An explicit
undefinedstepDaysis the default step, so(start, end, undefined, options)reachesoptions. Compatibility: before 1.16.0 it returned[]. - End-inclusive, where the
interval*functions are half-open. This enumerates the dates a range covers, soendDateis one of them; an interval bounds a span as[start, end), so itsendis not. The same pair therefore yields one more date here thanintervalCountDatecounts. To read one set of bounds both ways, passaddDate(endDate, { days: 1 })to theinterval*call, orsubtractDate(endDate, { days: 1 })to this one.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
startDate | string | ISO PlainDate string for the first date |
endDate | string | ISO PlainDate string for the last date (inclusive) |
stepDays | number | optional number of days to step between results |
Options
Section titled “Options”options
The limit on the size of the result
| Option | Type | Default | Description |
|---|---|---|---|
maxPieces? | number | 1_000_000 | The most dates 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 ISO PlainDate strings, or [] on invalid input
Examples
Section titled “Examples”import { mapDatesInRange } from "@northguild/gmt/plain/map";
mapDatesInRange("2024-03-01", "2024-03-05") // ["2024-03-01", "2024-03-02", "2024-03-03", "2024-03-04", "2024-03-05"]