1

i'm trying to get the number of weeks i a month in javascript.
I read a thread on the same subject -> Get Weeks In Month Through Javascript but when using the advised js lib, called "time.js", i havent good results for 2010.

Example:

When i use weeksInMonth() for september 2010 like :

weeksNbr = new Time(2010, 9).weeksInMonth();

The result is 6 but september 2010 has only 5 weeks ....
Someone have another way to do that or could explain me whats the bug ?

Community
  • 1
  • 1
Geraud Mathe
  • 711
  • 2
  • 9
  • 20

1 Answers1

1

javascript months start with 0 (January), so setMonth(9) is Octiober.

The first two days in October 2010 are in the week that began in September, and the last day is the first day of the first week in November. In between are four full weeks.

To make a calendar where weeks start on Sunday, you need all 6 weeks.

kennebec
  • 102,654
  • 32
  • 106
  • 127
  • Actually that only makes sense if your week starts on a Sunday. If like in this part of the world where I live in weeks start on a monday, then the function actually returns the wrong answer. I suppose the time.js library has a function that can redefine the "start of the week" day, but should it not, than I suppose a slight modification of that library function is required for the correct result – Ramuns Usovs Nov 10 '10 at 14:48
  • ok I found where's my bug. I'm french and we use to begin the week at monday so There is no bug only a difference with the library and what i want – Geraud Mathe Nov 10 '10 at 15:17