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

Function eachHourOfInterval

pkgs/core/src/eachHourOfInterval/index.ts:57–86  ·  view source on GitHub ↗
(
  interval: IntervalType,
  options?: Options,
)

Source from the content-addressed store, hash-verified

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

Callers 3

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

Calls 2

normalizeIntervalFunction · 0.90
constructFromFunction · 0.90

Tested by

no test coverage detected