getAllDaysInCalendar
code:mod.ts
import {
endOfMonth,
startOfMonth,
startOfWeek,
endOfWeek,
eachDayOfInterval,
isSunday
} from "../date-fns/mod.ts";
export const getAllDaysInCalendar = (date: Date): Date[][] => {
const start = startOfWeek(startOfMonth(date));
const end = endOfWeek(endOfMonth(date));
const days = eachDayOfInterval({ start, end });
return days.reduce(
(acc, cur, i) => {
if (isSunday(cur)) {
return acc;
}
acc.at(-1)!.push(cur);
return acc;
},
[]
);
};