From 49f143f5b03531902f44b0fea4d5ff65fa5cb5cf Mon Sep 17 00:00:00 2001 From: LWY <1938571424@qq.com> Date: Tue, 25 Aug 2026 16:21:23 +0800 Subject: [PATCH] fix(web): show recent session times in local timezone Home cards stripped the Z from UTC ISO strings and printed the digits as wall-clock time, so China (UTC+8) users saw times ~8h behind. Parse as Instant and format with toLocaleString using the browser timezone. Co-authored-by: Cursor --- frontend/src/pages/Home.tsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 476e48a5e..0225db3d7 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -17,13 +17,33 @@ interface RecentSession extends ChatSessionItem { kbIndex: number } -function formatWhen(iso: string): string { +/** + * Format a session timestamp for the recent-sessions cards. + * + * Backend stores UTC (`…Z`, see `openkb.agent.chat_session._utcnow_iso`). + * Never strip the `Z` and print the digits as-is — that shows UTC wall-clock + * and looks ~8h behind in China (UTC+8). Parse as an absolute Instant and + * format in the browser's local timezone; use the UI language only for the + * locale (digit/order style), not to hard-code a geographic zone. + */ +function formatWhen(iso: string, locale: string): string { if (!iso) return "" - return iso.replace("T", " ").replace("Z", "").slice(0, 16) + const d = new Date(iso) + if (Number.isNaN(d.getTime())) return iso + // zh → zh-CN (Asia-friendly date order); en → en-US. Timezone = local. + const loc = locale.toLowerCase().startsWith("zh") ? "zh-CN" : locale || undefined + return d.toLocaleString(loc, { + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + hour12: false, + }) } export default function Home() { - const { t } = useTranslation("home") + const { t, i18n } = useTranslation("home") const navigate = useNavigate() const location = useLocation() as { state?: { kbId?: string } } const [kbs, setKbs] = useState([]) @@ -116,7 +136,7 @@ export default function Home() { {s.updated_at && ( <> · - {formatWhen(s.updated_at)} + {formatWhen(s.updated_at, i18n.language)} )}