rty
rty

Reputation: 147

d3.js month.range interval issue

I have issue with d3 time interval with month interval.

var start =d3.time.month.utc(new Date(2009, 9, 5));
//Date {Thu Oct 01 2009 05:30:00 GMT+0530 (India Standard Time)}
var end = d3.time.month.utc(new Date(2011, 2, 5));
//Date {Tue Mar 01 2011 05:30:00 GMT+0530 (India Standard Time)}
d3.time.months.utc(start, end, 3) // interval of 3 months
returns
//[Date {Thu Oct 01 2009 05:30:00 GMT+0530 (India Standard Time)}, Date {Fri Jan 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Thu Apr 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Thu Jul 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Fri Oct 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Sat Jan 01 2011 05:30:00 GMT+0530 (India Standard Time)}]

Then now i am changing the start value month to september

var start = d3.time.month.utc(new Date(2009, 8, 5))
//Date {Tue Sep 01 2009 05:30:00 GMT+0530 (India Standard Time)}
d3.time.months.utc(start, end, 3) // interval of 3 months
//[Date {Thu Oct 01 2009 05:30:00 GMT+0530 (India Standard Time)}, Date {Fri Jan 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Thu Apr 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Thu Jul 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Fri Oct 01 2010 05:30:00 GMT+0530 (India Standard Time)}, Date {Sat Jan 01 2011 05:30:00 GMT+0530 (India Standard Time)}]

Both behaves same,giving same output, though i change the input month. What goes wrong here?

Upvotes: 0

Views: 628

Answers (1)

Lars Kotthoff
Lars Kotthoff

Reputation: 109232

You are specifying a step size of three, so it rounds to the nearest quarter (October 1st). This quarter is closest to both of the dates you specify, so it's returned for both.

Observe the difference when calling d3.time.months.utc(start, end, 1).

Upvotes: 1

Related Questions