diff --git a/src/interval.js b/src/interval.js index 492ae90..ddabf13 100644 --- a/src/interval.js +++ b/src/interval.js @@ -52,7 +52,7 @@ export function timeInterval(floori, offseti, count, field) { interval.count = (start, end) => { t0.setTime(+start), t1.setTime(+end); floori(t0), floori(t1); - return Math.floor(count(t0, t1)); + return Math.round(count(t0, t1)); }; interval.every = (step) => { diff --git a/test/dst-count-test.js b/test/dst-count-test.js new file mode 100644 index 0000000..b040b98 --- /dev/null +++ b/test/dst-count-test.js @@ -0,0 +1,24 @@ +import assert from "node:assert"; +import {it} from "vitest"; +import {timeDay, timeWeek} from "d3-time"; + +// Issue #74: in time zones where DST starts at 00:00 (e.g. America/Santiago), +// timeDay.floor of the transition day is 01:00. The count functions must still +// return the number of interval boundaries after start (exclusive), including +// the floored boundary itself when start is already aligned. +it("timeDay.count counts boundaries after a skipped-midnight start", () => { + const start = timeDay.floor(new Date(2025, 8, 7, 12)); + const next = timeDay.floor(new Date(2025, 8, 8, 12)); + const end = new Date(2025, 8, 17); + const expected = timeDay.range(new Date(+start + 1), new Date(+end + 1)).length; + assert.strictEqual(timeDay.count(start, next), 1); + assert.strictEqual(timeDay.count(start, end), expected); +}); + +it("timeWeek.count counts boundaries after a skipped-midnight start", () => { + const start = timeDay.floor(new Date(2025, 8, 7, 12)); + const end = new Date(2025, 8, 17); + // start is a Sunday (floored), end is a Wednesday; count the Sundays after start. + const expected = timeWeek.range(new Date(+start + 1), new Date(+end + 1)).length; + assert.strictEqual(timeWeek.count(start, end), expected); +});