diff --git a/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.test.mjs b/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.test.mjs index 8fb2c7c..87070c2 100644 --- a/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.test.mjs +++ b/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.test.mjs @@ -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) +}) diff --git a/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.ts b/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.ts index 4d895f4..d52e16f 100644 --- a/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.ts +++ b/web/app/dashboard/agent-team-schedules/_components/calendar-date-range.ts @@ -12,6 +12,10 @@ export function startOfWeek(date: Date) { return ret } +export function isSameLocalDay(a: Date, b: Date) { + return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate() +} + export function startOfMonth(date: Date) { const ret = startOfDay(date) ret.setDate(1) diff --git a/web/app/dashboard/agent-team-schedules/_components/calendar.tsx b/web/app/dashboard/agent-team-schedules/_components/calendar.tsx index 1368e31..bb44dd3 100644 --- a/web/app/dashboard/agent-team-schedules/_components/calendar.tsx +++ b/web/app/dashboard/agent-team-schedules/_components/calendar.tsx @@ -10,6 +10,7 @@ import type { UpdateAdminAgentTeamSchedulePayload, } from "@/lib/api/admin" import { cn, formatDateTime } from "@/lib/utils" +import { isSameLocalDay } from "./calendar-date-range" import { buildDayTimeLayout } from "./calendar-time-layout" const weekDayNames = ["一", "二", "三", "四", "五", "六", "日"] @@ -131,10 +132,6 @@ function isHistoricalDay(day: Date) { return startOfDay(day).getTime() < startOfDay(new Date()).getTime() } -function isSameLocalDay(a: Date, b: Date) { - return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate() -} - function buildMovePayload(item: AdminAgentTeamSchedule, date: string): UpdateAdminAgentTeamSchedulePayload { const originalStart = parseLocalDateTime(item.startAt) const originalEnd = parseLocalDateTime(item.endAt) @@ -380,6 +377,7 @@ export function ScheduleCalendar({ const date = formatDate(day) const inMonth = options?.inMonth ?? day.getMonth() === monthStart.getMonth() const historical = isHistoricalDay(day) + const today = isSameLocalDay(day, new Date()) const daySchedules = schedules .filter((item) => intersectsDay(item, day)) .sort((a, b) => parseLocalDateTime(a.startAt).getTime() - parseLocalDateTime(b.startAt).getTime()) @@ -428,7 +426,14 @@ export function ScheduleCalendar({