Last active
August 21, 2023 18:09
-
-
Save YonatanKra/f3fc5927eff52754f224f356f4bc2e6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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