Quote:
The first thing we need to do is to work out how we define when a week starts and finishes and how we determine which week a particular date is in. The getDay() method returns a value of 0 for Sunday and 6 for Saturday so let's start by defining our week as running from Sunday to Saturday. The 1st January can fall on any day of the week and so not all of the days in that week will be in the current year but we'll consider the week that contains the 1st January to be week one of the current year even though not all of the days in that week are necessarily in the current year. So week one consists of those days between 1st January and the first Saturday on or after that date and the seven days following that make up week two and so on. Once we get to the end of December the last few days of the year will be in week 53 (or possibly 54 if it is a leap year starting on a Saturday).
I wonder about Leap Year 2012 and the fact that days, months, etc. start with zero.