Here's a demonstration expanding on the concept presented in this Stack Overflow post about calculating date from week number using JavaScript
Start by finding the first date of the week, then generate an array of 7 elements with each element representing a day in that week.
If the day exceeds the total days in the month, increment the month and reset the day to 1.
function getISOWeek(w, y) {
var simple = new Date(y, 0, 1 + (w - 1) * 7);
var dow = simple.getDay();
var ISOweekStart = simple;
if (dow <= 4)
ISOweekStart.setDate(simple.getDate() - simple.getDay() + 1);
else
ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay());
const temp = {
d: ISOweekStart.getDate(),
m: ISOweekStart.getMonth(),
y: ISOweekStart.getFullYear(),
}
const numDaysInMonth = new Date(temp.y, temp.m + 1, 0).getDate()
return Array.from({length: 7}, _ => {
if (temp.d > numDaysInMonth){
temp.m +=1;
temp.d = 1;
}
return new Date(temp.y, temp.m, temp.d++).toUTCString()
});
}
const weekNumber = "53 2020";
const weekYearArr = weekNumber.split(" ").map(n => parseInt(n))
const weekOut = getISOWeek(...weekYearArr)
console.log(weekOut);
Input: "35 2020"
Output:
[
"Sun, 23 Aug 2020 22:00:00 GMT",
"Mon, 24 Aug 2020 22:00:00 GMT",
"Tue, 25 Aug 2020 22:00:00 GMT",
"Wed, 26 Aug 2020 22:00:00 GMT",
"Thu, 27 Aug 2020 22:00:00 GMT",
"Fri, 28 Aug 2020 22:00:00 GMT",
"Sat, 29 Aug 2020 22:00:00 GMT"
]
input : "36 2020"
output:
[
"Sun, 30 Aug 2020 22:00:00 GMT",
"Mon, 31 Aug 2020 22:00:00 GMT",
"Tue, 01 Sep 2020 22:00:00 GMT",
"Wed, 02 Sep 2020 22:00:00 GMT",
"Thu, 03 Sep 2020 22:00:00 GMT",
"Fri, 04 Sep 2020 22:00:00 GMT",
"Sat, 05 Sep 2020 22:00:00 GMT"
]