UNPKG

571 BPlain TextView Raw
1import type { CalendarDay, CalendarMonth } from "../classes/index.js";
2
3/**
4 * Returns all the days belonging to the calendar by merging the days in the
5 * weeks for each month.
6 */
7export function getDays(calendarMonths: CalendarMonth[]) {
8 const initialDays: CalendarDay[] = [];
9 return calendarMonths.reduce((days, month) => {
10 const initialDays: CalendarDay[] = [];
11 const weekDays: CalendarDay[] = month.weeks.reduce((weekDays, week) => {
12 return [...weekDays, ...week.days];
13 }, initialDays);
14 return [...days, ...weekDays];
15 }, initialDays);
16}