Created
August 7, 2024 03:15
-
-
Save mpr0xy/d4fbb50eb7fc572471fce0f8ed8fbe80 to your computer and use it in GitHub Desktop.
Revisions
-
mpr0xy created this gist
Aug 7, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ function getDaysInWeek(year, month) { function getDaysInMonth(year, month) { return new Date(year, month, 0).getDate(); } const monthDays = getDaysInMonth(year, month); console.log(monthDays); let startDate = 1; const results = []; while (startDate <= monthDays) { const week = [0, 0, 0, 0, 0, 0, 0]; let day = new Date(year, month - 1, startDate).getDay(); day = day === 0 ? 6 : day - 1; week.forEach((item, index) => { if (index >= day && startDate <= monthDays) { week[index] = startDate; startDate++; } }); results.push(week); } return results; }