Skip to content

mapDatesInRange

mapDatesInRange(startDate: string, endDate: string, stepDays?: number): string[]
import { mapDatesInRange } from "@northguild/gmt/plain/map";

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.
Parameter Type Description
startDate string ISO PlainDate string for the first date
endDate string ISO PlainDate string for the last date (inclusive)
stepDays `` optional number of days to step between results

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

mapDatesInRange("2024-03-01", "2024-03-05") // ["2024-03-01", "2024-03-02", "2024-03-03", "2024-03-04", "2024-03-05"]
mapDatesInRange("2024-03-01", "2024-03-05", 2) // ["2024-03-01", "2024-03-03", "2024-03-05"]
mapDatesInRange("2024-03-05", "2024-03-01") // []
mapDatesInRange("invalid", "2024-03-05") // []
mapDatesInRange("2024-03-01", "invalid") // []
mapDatesInRange("2024-03-01", "2024-03-05", 0) // []

plain/map/mapDatesInRange.ts