Filtered intervals' offset() function doesn't work correctly when step is negative
douglyuckling opened this issue · comments
Douglas Paul commented
The offset() function of filtered intervals doesn't seem to work as intended when the given step is negative:
const interval = d3.utcMinute.every(15);
const date = new Date("Fri, 14 Jul 2017 12:07:23 GMT");
console.log(interval.offset(date, 1).toUTCString()); // Fri, 14 Jul 2017 12:15:23 GMT (correct)
console.log(interval.offset(date, -1).toUTCString()); // Fri, 14 Jul 2017 12:07:23 GMT (incorrect)
(Here's a runnable version on CodePen.)
Looking at the D3 code, the problem is pretty clear:
if (date >= date) while (--step >= 0) while (offseti(date, 1), !test(date)) {}
Mike Bostock commented
Fixed in 1.0.7. Thanks for the report!