Geraud Mathe
Geraud Mathe

Reputation: 711

Using time.js, i Have wrong results about weeks number in a month

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 ?

Upvotes: 1

Views: 260

Answers (1)

kennebec
kennebec

Reputation: 104800

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.

Upvotes: 1

Related Questions