diff --git a/src/options.js b/src/options.js index 51043a854e..dc1b1c842b 100644 --- a/src/options.js +++ b/src/options.js @@ -426,7 +426,7 @@ export function maybeNiceInterval(interval, type) { } export function isTimeInterval(t) { - return isInterval(t) && typeof t?.floor === "function" && t.floor() instanceof Date; + return isInterval(t) && typeof t?.floor === "function"; } export function isInterval(t) { diff --git a/test/options-test.js b/test/options-test.js index e2c0634f6e..4eedaec3e7 100644 --- a/test/options-test.js +++ b/test/options-test.js @@ -1,5 +1,5 @@ import {assert, it} from "vitest"; -import {identity, isNumericString, valueof} from "../src/options.js"; +import {identity, isNumericString, valueof, isTimeInterval} from "../src/options.js"; import {isYearInteger, isYearIntegers} from "../src/options.js"; it("isYearInteger returns true for integers in [1500, 2500]", () => { @@ -74,6 +74,12 @@ it("isNumericString only checks the first present value", () => { assert.strictEqual(isNumericString(["notstring", "42"]), false); }); +it("isTimeInterval returns true for interval-like objects with a date floor", () => { + assert.strictEqual(isTimeInterval({range: () => [new Date()], floor: () => new Date()}), true); + assert.strictEqual(isTimeInterval({range: () => [0], floor: () => 0}), false); + assert.strictEqual(isTimeInterval({range: () => [0]}), false); +}); + it("valueof returns nullish value", () => { assert.strictEqual(valueof([], null), null); assert.strictEqual(valueof([], undefined), undefined);