Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active August 21, 2023 18:09
Show Gist options
  • Save YonatanKra/f3fc5927eff52754f224f356f4bc2e6a to your computer and use it in GitHub Desktop.
Save YonatanKra/f3fc5927eff52754f224f356f4bc2e6a to your computer and use it in GitHub Desktop.
const grid = [];
let week: CalendarGridDate[] = [];
const lastDay = new Date(year, month + 1, 0);
const firstDayInWeek = getDay(firstDay);
const daysInMonth = lastDay.getDate();
const daysOutsideMonthInLastWeek = 7 - getDay(lastDay);
const totalDaysInCalendar = daysInMonth + firstDayInWeek + daysOutsideMonthInLastWeek;
for (let i = 0; i < totalDaysInCalendar; i++) {
const dayIndexInMonth = i - firstDayInWeek;
week.push(createGridDate(addDays(firstDay, dayIndexInMonth), isOutsideMonth(dayIndexInMonth, daysInMonth)));
if (week.length === 7) {
grid.push(week);
week = [];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment