feat(calendar): add isSameLocalDay function and integrate it into calendar components

This commit is contained in:
mlogclub
2026-04-29 14:54:19 +08:00
parent 9d9687ec5a
commit e56fe82b3a
4 changed files with 33 additions and 6 deletions
@@ -1,7 +1,7 @@
import assert from "node:assert/strict"
import test from "node:test"
import { addDays, formatWeekTitle, startOfWeek } from "./calendar-date-range.ts"
import { addDays, formatWeekTitle, isSameLocalDay, startOfWeek } from "./calendar-date-range.ts"
test("builds Monday-based week range and title", () => {
const start = startOfWeek(new Date(2026, 3, 29, 14, 0, 0))
@@ -12,3 +12,8 @@ test("builds Monday-based week range and title", () => {
assert.equal(formatWeekTitle(start), "2026-04-27 - 2026-05-03")
assert.equal(addDays(start, 7).getDate(), 4)
})
test("compares local calendar dates", () => {
assert.equal(isSameLocalDay(new Date(2026, 3, 29, 0, 0), new Date(2026, 3, 29, 23, 59)), true)
assert.equal(isSameLocalDay(new Date(2026, 3, 29, 23, 59), new Date(2026, 3, 30, 0, 0)), false)
})