MCPcopy
hub / github.com/date-fns/date-fns / eachDayOfInterval

Function eachDayOfInterval

pkgs/core/src/eachDayOfInterval/index.ts:60–90  ·  view source on GitHub ↗
(
  interval: IntervalType,
  options?: Options,
)

Source from the content-addressed store, hash-verified

58 * // ]
59 */
60export function eachDayOfInterval<
61 IntervalType extends Interval,
62 Options extends EachDayOfIntervalOptions | undefined = undefined,
63>(
64 interval: IntervalType,
65 options?: Options,
66): EachDayOfIntervalResult<IntervalType, Options> {
67 const { start, end } = normalizeInterval(options?.in, interval);
68
69 let reversed = +start > +end;
70 const endTime = reversed ? +start : +end;
71 const date = reversed ? end : start;
72 date.setHours(0, 0, 0, 0);
73
74 let step = options?.step ?? 1;
75 if (!step) return [];
76 if (step < 0) {
77 step = -step;
78 reversed = !reversed;
79 }
80
81 const dates: EachDayOfIntervalResult<IntervalType, Options> = [];
82
83 while (+date <= endTime) {
84 dates.push(constructFrom(start, date));
85 date.setDate(date.getDate() + step);
86 date.setHours(0, 0, 0, 0);
87 }
88
89 return reversed ? dates.reverse() : dates;
90}

Callers 5

basic.tsFile · 0.90
test.tsFile · 0.90
_testFunction · 0.90
eachWeekendOfIntervalFunction · 0.90
tests.tsFile · 0.85

Calls 2

normalizeIntervalFunction · 0.90
constructFromFunction · 0.90

Tested by

no test coverage detected