views:

39

answers:

3

I see Google's example code listing dates for January, but the chart is displaying dates for February!

On my test machine, it is doing the same thing. I've told it to display dates for September, but it is displaying dates for October instead!

Can anyone else confirm this as happening?

http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html

A: 

No, you're not losing your mind. The month in the Javascript Date object is zero-indexed. That means:

0  = January
1  = February
2  = March
3  = April
4  = May
5  = June
6  = July
7  = August
8  = September
9  = October
10 = November
11 = December
In silico
+3  A: 

The months in the javascript date are 0 based not 1 based. So 0 is Jan, 1 is Feb, etc. See http://www.w3schools.com/js/js_obj_date.asp and you might want to check out http://en.wikipedia.org/wiki/Off-by-one_error

Dror
Oh my God, wow. I would never have guessed they'd do that to Months. I was just going to subtract by 1, but it seemed like such a hack. Now it doesn't. Thanks a lot.
Tylo
Yeah, it's certainly counter-intuitive when you look at a date.
Dror
A: 

ECMA-262 5ed, pp.165:

15.9.1.4 Month Number

Months are identified by an integer in the range 0 to 11, inclusive.

livibetter