I have the following piece of code written in react-spfx:
private weekNumber(){const months = \["January","February","March","April","May","June","July","August","September","October","November","December"\];var currentWeek = (document.getElementById('myweek') as HTMLInputElement).value;var currentDate = new Date(currentWeek);var fullYear = new Date(currentDate.getFullYear(),0,1);var myMonth = months\[currentDate.getMonth()\];date = currentWeek;var givenDate = currentDate.getDate();var givenDay = currentDate.getDay();var weekNo = //require this logic to be framed//......monthWeekNo = myMonths +"- Week No. " + weekNo;}
For example if I select 6th December from the calender, the desired output ie monthWeekNo should show December- Week No. 2
Consider this calender. I have taken Friday as reference and based on that I will be assigning the week based on the selection of my date. For example, in the given calender picture you can see December 2nd is the first week because it falls on Friday. Then in that case all the dates starting from Nov 28th(Monday) to Dec 4th(Sunda) should fall on 1st week of December i.e., if e.g., I select 29th Nov 2022, then the output of monthWeekNo should show "December- Week No. 1".
Let's say for this calender I selected Jan 1st 2023, my output of monthWeekNo. should show "December- Week No. 5". This is because Friday December 30th is the reference in this case and all the dates ranging from Monday December 26th '22 to Sunday Jan 1st '23 falls on Week 5 of December.
Can someone brainstorm on this and provide a solution for the same?