Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

Framing a logic for getting the week number using spfx react keeping Friday as the reference for calculation [closed]

$
0
0

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;}

Example calender

For example if I select 6th December from the calender, the desired output ie monthWeekNo should show December- Week No. 2

Calender reference-1

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".

Calender reference-2

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?


Viewing all articles
Browse latest Browse all 6290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>