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

Function eachWeekOfInterval

pkgs/core/src/eachWeekOfInterval/index.ts:71–111  ·  view source on GitHub ↗
(
  interval: IntervalType,
  options?: Options,
)

Source from the content-addressed store, hash-verified

69 * // ]
70 */
71export function eachWeekOfInterval<
72 IntervalType extends Interval,
73 Options extends EachWeekOfIntervalOptions | undefined = undefined,
74>(
75 interval: IntervalType,
76 options?: Options,
77): EachWeekOfIntervalResult<IntervalType, Options> {
78 const { start, end } = normalizeInterval(options?.in, interval);
79
80 let reversed = +start > +end;
81 const startDateWeek = reversed
82 ? startOfWeek(end, options)
83 : startOfWeek(start, options);
84 const endDateWeek = reversed
85 ? startOfWeek(start, options)
86 : startOfWeek(end, options);
87
88 startDateWeek.setHours(15);
89 endDateWeek.setHours(15);
90
91 const endTime = +endDateWeek.getTime();
92 let currentDate = startDateWeek;
93
94 let step = options?.step ?? 1;
95 if (!step) return [];
96 if (step < 0) {
97 step = -step;
98 reversed = !reversed;
99 }
100
101 const dates: EachWeekOfIntervalResult<IntervalType, Options> = [];
102
103 while (+currentDate <= endTime) {
104 currentDate.setHours(0);
105 dates.push(constructFrom(start, currentDate));
106 currentDate = addWeeks(currentDate, step);
107 currentDate.setHours(15);
108 }
109
110 return reversed ? dates.reverse() : dates;
111}

Callers 3

test.tsFile · 0.90
_testFunction · 0.90
test.tsFile · 0.90

Calls 4

normalizeIntervalFunction · 0.90
startOfWeekFunction · 0.90
constructFromFunction · 0.90
addWeeksFunction · 0.90

Tested by

no test coverage detected