Following is the code that calculates the week date,
//Gets the week dayNumber date against the year,week number
var getWeekDate = function (year, weekNumber, dayNumber) {
var date = new Date(year, 0, 10, 0, 0, 0),
day = new Date(year, 0, 4, 0, 0, 0),
month = day.getTime() - date.getDay() * 86400000;
return new Date(month + ((weekNumber - 1) * 7 + dayNumber) * 86400000);
};
The code is working fine if I give the following values,
Input:
year = 2012
weekNumber = 1
dayNumber = 0 //My week starts from monday, so I am giving it 0.
Output:
2nd,Jan 2012 //That's correct.
Input:
year = 2013
weekNumber = 1
dayNumber = 0 //My week starts from monday, so I am giving it 0.
Output:
31st,DEC 2012 //That's in-correct.
The first week of 2013 will start from 7th, Jan 2013 i.e.Monday but the above code is not calculating it correctly.