d3 / d3-time

A calculator for humanity’s peculiar conventions of time.

Home Page:https://d3js.org/d3-time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filtered intervals' offset() function doesn't work correctly when step is negative

douglyuckling opened this issue · comments

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

Fixed in 1.0.7. Thanks for the report!