Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 794 Bytes

README.md

File metadata and controls

42 lines (28 loc) · 794 Bytes

dayjs-range-support

Add dayjs.range() to yield each day between some period

npm install -S @fsubal/dayjs-range-support
yarn add @fsubal/dayjs-range-support

Usage

dayjs.range() returns a generator (not dayjs.Dayjs[])!

Array.from(dayjs.range('2020-12-01', '2020-12-31'))
[...dayjs.range('2020-12-01', '2020-12-31')]

for (const day of dayjs.range('2020-12-01', '2020-12-31')) {
  ...
}
dayjs.range("2020-12-01", "2020-12-12", {
  step: [2, "day"],
});

Options

dayjs.range() accepts options as the 3rd argument.

excludeEnd: boolean (optional)

Whether to exclude the last date from range.

step: [number, string] (optional)

Step between each date. Accepts the same type as dayjs.add() ( For example, [2, 'day'] ).