Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
24 changes: 24 additions & 0 deletions test/dst-count-test.js
Original file line number Diff line number Diff line change
@@ -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);
});