Skip to content

Commit 49f143f

Browse files
lwylabcursoragent
andcommitted
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 <cursoragent@cursor.com>
1 parent ff54396 commit 49f143f

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

‎frontend/src/pages/Home.tsx‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,33 @@ interface RecentSession extends ChatSessionItem {
1717
kbIndex: number
1818
}
1919

20-
function formatWhen(iso: string): string {
20+
/**
21+
* Format a session timestamp for the recent-sessions cards.
22+
*
23+
* Backend stores UTC (`…Z`, see `openkb.agent.chat_session._utcnow_iso`).
24+
* Never strip the `Z` and print the digits as-is — that shows UTC wall-clock
25+
* and looks ~8h behind in China (UTC+8). Parse as an absolute Instant and
26+
* format in the browser's local timezone; use the UI language only for the
27+
* locale (digit/order style), not to hard-code a geographic zone.
28+
*/
29+
function formatWhen(iso: string, locale: string): string {
2130
if (!iso) return ""
22-
return iso.replace("T", " ").replace("Z", "").slice(0, 16)
31+
const d = new Date(iso)
32+
if (Number.isNaN(d.getTime())) return iso
33+
// zh → zh-CN (Asia-friendly date order); en → en-US. Timezone = local.
34+
const loc = locale.toLowerCase().startsWith("zh") ? "zh-CN" : locale || undefined
35+
return d.toLocaleString(loc, {
36+
year: "numeric",
37+
month: "2-digit",
38+
day: "2-digit",
39+
hour: "2-digit",
40+
minute: "2-digit",
41+
hour12: false,
42+
})
2343
}
2444

2545
export default function Home() {
26-
const { t } = useTranslation("home")
46+
const { t, i18n } = useTranslation("home")
2747
const navigate = useNavigate()
2848
const location = useLocation() as { state?: { kbId?: string } }
2949
const [kbs, setKbs] = useState<KbSummary[]>([])
@@ -116,7 +136,7 @@ export default function Home() {
116136
{s.updated_at && (
117137
<>
118138
<span className="opacity-50">·</span>
119-
{formatWhen(s.updated_at)}
139+
{formatWhen(s.updated_at, i18n.language)}
120140
</>
121141
)}
122142
<ArrowRight className="w-3.5 h-3.5 ml-auto opacity-0 -translate-x-1 group-hover:opacity-100 group-hover:translate-x-0 transition-all text-accent-brand" />

0 commit comments

Comments
 (0)