Interesting problem. Here's my solution:
var week2date = (function() {
var weekToDate = {
// last week number in the month: [first date of each week]
4: [4, 11, 18, 25], // jan
8: [1, 8, 15, 22], // feb
13: [1, 8, 15, 22, 29], // march
17: [5, 12, 19, 26], // etc ...
22: [3, 10, 17, 24, 31],
26: [7, 14, 21, 28],
30: [5, 12, 19, 26],
35: [2, 9, 16, 23, 30],
39: [6, 13, 20, 27],
43: [4, 11, 18, 25],
48: [1, 8, 15, 22, 29],
52: [6, 13, 20, 27]
};
return function(week, year) {
if ( week > 52 || week < 01 ) { return false; }
var d = new Date(),
lastw = 0,
month = 0;
for ( var w in weekToDate ) {
if ( !weekToDate.hasOwnProperty(w) ) { continue; }
if ( w >= week ) {
break;
}
lastw = w;
++month;
}
d.setFullYear(year || d.getFullYear(), month, weekToDate[w][week - lastw - 1]);
return d;
}
})();
Use:
console.log(week2date(13));
console.log(week2date(38, 1983));
Output:
Mon Mar 29 2010 18:51:28 GMT-0700 (PST) {}
Tue Sep 20 1983 18:51:28 GMT-0700 (PST) {}
I used this table on wikipedia to get the date information.