AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): format sidebar date group labels with the user's locale (#14437)
gaoanze8881fa59a0f57f5
diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.ts b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.tsindex 8e7787bf4e..93e4d108ef 100644--- a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.ts+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/__tests__/helpers.test.ts@@ -35,28 +35,26 @@ describe("getDateGroupLabel", () => {expect(getDateGroupLabel(isoDaysAgo(1))).toBe("Yesterday");});- it("labels an older same-year date with an ordinal day and month", () => {- // 2026-06-20 -> "20th June"- const label = getDateGroupLabel("2026-06-20T08:00:00");- expect(label).toBe("20th June");+ it("labels an older same-year date with month and day", () => {+ // 2026-06-20 -> "June 20"+ const label = getDateGroupLabel("2026-06-20T08:00:00", "en-US");+ expect(label).toBe("June 20");});it("includes the year for dates in a previous year", () => {- const label = getDateGroupLabel("2024-12-01T08:00:00");- expect(label).toBe("1st December 2024");+ const label = getDateGroupLabel("2024-12-01T08:00:00", "en-US");+ expect(label).toBe("December 1, 2024");});- it("uses 'st', 'nd', 'rd', 'th' ordinal suffixes correctly", () => {- expect(getDateGroupLabel("2026-06-01T08:00:00")).toBe("1st June");- expect(getDateGroupLabel("2026-06-02T08:00:00")).toBe("2nd June");- expect(getDateGroupLabel("2026-06-03T08:00:00")).toBe("3rd June");- expect(getDateGroupLabel("2026-06-04T08:00:00")).toBe("4th June");- });-- it("uses 'th' for the 11th–13th teen exceptions", () => {- expect(getDateGroupLabel("2026-06-11T08:00:00")).toBe("11th June");- expect(getDateGroupLabel("2026-06-12T08:00:00")).toBe("12th June");- expect(getDateGroupLabel("2026-06-13T08:00:00")).toBe("13th June");+ it("formats the date end-to-end in the user's locale", () => {+ // The label must come from a single locale-aware formatter, not from+ // hand-assembled English-style parts ("20th 六月"-style mixes).+ expect(getDateGroupLabel("2026-06-20T08:00:00", "en-GB")).toBe("20 June");+ expect(getDateGroupLabel("2026-06-20T08:00:00", "de-DE")).toBe("20. Juni");+ expect(getDateGroupLabel("2026-06-20T08:00:00", "zh-CN")).toBe("6月20日");+ expect(getDateGroupLabel("2024-12-01T08:00:00", "zh-CN")).toBe(+ "2024年12月1日",+ );});});@@ -84,11 +82,11 @@ describe("groupSessionsByDate", () => {{ id: "today", updated_at: isoDaysAgo(0) },{ id: "yesterday", updated_at: isoDaysAgo(1) },];- const groups = groupSessionsByDate(sessions);+ const groups = groupSessionsByDate(sessions, "en-US");expect(groups.map((g) => g.label)).toEqual(["Today","Yesterday",- getDateGroupLabel(isoDaysAgo(5)),+ getDateGroupLabel(isoDaysAgo(5), "en-US"),]);});@@ -102,4 +100,12 @@ describe("groupSessionsByDate", () => {expect(groups).toHaveLength(1);expect(groups[0].sessions.map((s) => s.id)).toEqual(["1", "2", "3"]);});++ it("labels groups in the given locale", () => {+ const groups = groupSessionsByDate(+ [{ id: "a", updated_at: "2026-06-20T08:00:00" }],+ "de-DE",+ );+ expect(groups[0].label).toBe("20. Juni");+ });});diff --git a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.ts b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.tsindex 89039d5539..2210829bd8 100644--- a/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.ts+++ b/autogpt_platform/frontend/src/components/layout/AppSidebar/components/RecentChats/helpers.ts@@ -12,34 +12,23 @@ function diffInDays(iso: string): number {return Math.round((startOfDay(new Date()) - startOfDay(date)) / dayMs);}-function ordinalSuffix(day: number): string {- if (day >= 11 && day <= 13) return "th";- switch (day % 10) {- case 1:- return "st";- case 2:- return "nd";- case 3:- return "rd";- default:- return "th";- }-}--// e.g. "26th June" (current year) or "26th June 2024" (older).-function formatDayLabel(date: Date): string {- const day = date.getDate();- const month = date.toLocaleDateString(undefined, { month: "long" });- const label = `${day}${ordinalSuffix(day)} ${month}`;+// e.g. "June 26" (current year) or "December 1, 2024" (older), in the user's+// locale. A single Intl.DateTimeFormat options set keeps the format valid for+// every locale instead of hand-assembling English-style date parts.+function formatDayLabel(date: Date, locale?: string): string {const sameYear = date.getFullYear() === new Date().getFullYear();- return sameYear ? label : `${label} ${date.getFullYear()}`;+ return new Intl.DateTimeFormat(locale, {+ day: "numeric",+ month: "long",+ ...(sameYear ? {} : { year: "numeric" }),+ }).format(date);}-export function getDateGroupLabel(iso: string): string {+export function getDateGroupLabel(iso: string, locale?: string): string {const diffDays = diffInDays(iso);if (diffDays <= 0) return "Today";if (diffDays === 1) return "Yesterday";- return formatDayLabel(new Date(iso));+ return formatDayLabel(new Date(iso), locale);}// Buckets sessions by calendar day and orders groups most-recent-first. Doesn't@@ -47,6 +36,7 @@ export function getDateGroupLabel(iso: string): string {// duplicate day groups; within a group, input order is preserved.export function groupSessionsByDate<T extends { updated_at: string }>(sessions: T[],+ locale?: string,): { label: string; sessions: T[] }[] {const buckets = new Map<number, { label: string; sessions: T[] }>();@@ -57,7 +47,7 @@ export function groupSessionsByDate<T extends { updated_at: string }>(bucket.sessions.push(session);} else {buckets.set(dayKey, {- label: getDateGroupLabel(session.updated_at),+ label: getDateGroupLabel(session.updated_at, locale),sessions: [session],});}