MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / chatLabel

Function chatLabel

ui/src/components/workspace/ChatWorkspaceSection.tsx:37–46  ·  view source on GitHub ↗

Friendly label for a chat workspace: Today / Yesterday / "Jun 14" for daily * buckets, the raw tag for user-named workspaces.

(w: Workspace, todayLabel: string, yesterdayLabel: string)

Source from the content-addressed store, hash-verified

35/** Friendly label for a chat workspace: Today / Yesterday / "Jun 14" for daily
36 * buckets, the raw tag for user-named workspaces. */
37function chatLabel(w: Workspace, todayLabel: string, yesterdayLabel: string): string {
38 if (!DAILY_TAG_RE.test(w.tag)) return w.tag
39 const created = new Date(w.createdAt)
40 if (Number.isNaN(created.getTime())) return w.tag
41 const startOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime()
42 const diffDays = Math.round((startOfDay(new Date()) - startOfDay(created)) / 86_400_000)
43 if (diffDays <= 0) return todayLabel
44 if (diffDays === 1) return yesterdayLabel
45 return created.toLocaleDateString(getIntlLocale(), { month: 'short', day: 'numeric' })
46}
47
48export function ChatWorkspaceSection(): ReactElement | null {
49 const { t } = useTranslation()

Callers 1

ChatWorkspaceSectionFunction · 0.85

Calls 2

getIntlLocaleFunction · 0.90
startOfDayFunction · 0.85

Tested by

no test coverage detected