d3.js month.range间隔问题

时间:2014-05-13 11:30:53

标签: datetime d3.js

我有d3时间间隔与月间隔的问题。

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)}]

然后我现在将开始值月更改为9月

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)}]

虽然我改变了输入月份,但两者的行为相同,输出相同。 这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

您指定的步长为3,因此它会舍入到最接近的四分之一(10月1日)。本季度最接近您指定的两个日期,因此两者都会返回。

在致电d3.time.months.utc(start, end, 1)时注意区别。