Skip to content

mapDatesInRange

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 undefined stepDays is the default step, so (start, end, undefined, options) reaches options. Compatibility: before 1.16.0 it returned [].
  • End-inclusive, where the interval* functions are half-open. This enumerates the dates a range covers, so endDate is one of them; an interval bounds a span as [start, end), so its end is not. The same pair therefore yields one more date here than intervalCountDate counts. To read one set of bounds both ways, pass addDate(endDate, { days: 1 }) to the interval* call, or subtractDate(endDate, { days: 1 }) to this one.
ParameterTypeDescription
startDatestringISO PlainDate string for the first date
endDatestringISO PlainDate string for the last date (inclusive)
stepDaysnumberoptional number of days to step between results

options

The limit on the size of the result

OptionTypeDefaultDescription
maxPieces?number1_000_000The 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 [].

array of ISO PlainDate strings, or [] on invalid input

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"]
output 

plain/map/mapDatesInRange.ts