range

Generates a month sequence between two endpoints.

import { Month } from "@teakit/month";

Month.range("2025-01", "2025-03").map(String);
// ["2025-01", "2025-02", "2025-03"]

Month.range("2025-03", "2025-01").map(String);
// ["2025-03", "2025-02", "2025-01"]

Month.range("2025-01", "2025-06", { step: 2, inclusive: false }).map(String);
// ["2025-01", "2025-03", "2025-05"]

Month.range("2025-01-31", "2025-03-31").map((month) => month.toString({ precision: "day" }));
// ["2025-01-31", "2025-02-28", "2025-03-31"]

API Reference

Signature

Month.range(start: MonthValue, end: MonthValue, options?: MonthRangeOptions): MonthInstance[];

Parameters

ParameterTypeRequiredNotes
startMonthValueYesFirst month in the sequence.
endMonthValueYesBoundary month.
options.inclusivebooleanNoDefaults to true.
options.stepnumberNoSafe non-zero integer. Defaults to 1 for ascending ranges and -1 for descending ranges.

Returns

Returns an array of immutable MonthInstance values.

If the start value has a day anchor from a date-like string or native Date, generated values preserve that anchor for explicit day-precision output.

Throws

  • Throws when step is 0.
  • Throws when step moves away from end.

Agent Contract

FieldValue
Kindstatic sequence utility
Canonical namerange
AliasesNone
Mutates inputsNo
ReturnsMonthInstance[]

Agent Notes

  • Use .map(String) or .map((month) => month.toString()) when string output is needed.
  • Use .map((month) => month.toString({ precision: "day" })) only when the start value includes a day anchor and day-precision output is needed.
  • Be careful with large ranges because this method allocates the full array.