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/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion test/options-test.js
Original file line number Diff line number Diff line change
@@ -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]", () => {
Expand Down Expand Up @@ -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);
Expand Down