D3时间范围在第一个月下降

时间:2013-10-22 16:15:46

标签: javascript d3.js

在图书馆D3中。我发现处理日期的函数集有点不一致。例如,在页面加载D3的控制台中执行以下4个步骤,我得到:

> start = new Date(2010, 11, 30)
Thu Dec 30 2010 00:00:00 GMT+0000 (GMT Standard Time)
> end = new Date(2011, 0, 2)
Sun Jan 02 2011 00:00:00 GMT+0000 (GMT Standard Time)
> d3.time.months(start, end, 1)
[Sat Jan 01 2011 00:00:00 GMT+0000 (GMT Standard Time)]
> d3.time.days(start, end, 1)
[Thu Dec 30 2010 00:00:00 GMT+0000 (GMT Standard Time), Fri Dec 31 2010 00:00:00 GMT+0000 (GMT Standard Time), Sat Jan 01 2011 00:00:00 GMT+0000 (GMT Standard Time)]

以上表示day.range从第一项开始,在第二项之前结束,而month.range似乎则相反。

documentation中声明:

# d3.time.months(start, stop[, step])

Alias for d3.time.month.range. Returns the month boundaries (e.g., January 01)
after or equal to start and before stop. If step is specified, then every step'th
month will be returned, based on the month of the year. For example, a step of 3
will return January, April, July, etc.
after or equal to start and before stop也提到了

time.days,但结果似乎有所不同。此外,当这些函数在等于开始后返回时?有什么区别?

NB:我的愿望是让这些函数返回几天,几个月,几年的数组,包括两个开始和结束参数。

1 个答案:

答案 0 :(得分:0)

正如here中明确解释的那样,行为实际上是一致的。 day.rangemonth.range都旨在返回startend参数之间的每日和每月边界。