You need to find the start of the first week of the year, which can fall at the end of the previous year,
and the first week of the next year, which can be the end of the current year.
Most weeks are based on Monday, but you can use Sunday-
Monday based weeks begin the year with first week that contains a Thursday,
so we'll look for Wednesday instead.
(Some years contain 53 weeks)
I'll split it into two functions:
//get the first sunday of the first week of year y(or current year)
if(y== undefined) y= new Date().getFullYear();
var start= new Date(y, 0, 1);
while(start.getDay()!= 0) start.setDate(start.getDate()-1);
//get the week number of date now (or current day)
if(now== undefined) now= new Date();
var y= now.getFullYear(),
if(now> end) return 1; // first week of next calendar year
if(now<start) start= getWeek1(y-1);// last week of previous year