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

Function eachMinuteOfInterval

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

Source from the content-addressed store, hash-verified

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

Callers 2

test.tsFile · 0.90
_testFunction · 0.90

Calls 3

normalizeIntervalFunction · 0.90
constructFromFunction · 0.90
addMinutesFunction · 0.90

Tested by

no test coverage detected