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

Function eachQuarterOfInterval

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

Source from the content-addressed store, hash-verified

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

Callers 2

test.tsFile · 0.90
_testFunction · 0.90

Calls 4

normalizeIntervalFunction · 0.90
startOfQuarterFunction · 0.90
constructFromFunction · 0.90
addQuartersFunction · 0.90

Tested by

no test coverage detected