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)
| 35 | /** Friendly label for a chat workspace: Today / Yesterday / "Jun 14" for daily |
| 36 | * buckets, the raw tag for user-named workspaces. */ |
| 37 | function 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 | |
| 48 | export function ChatWorkspaceSection(): ReactElement | null { |
| 49 | const { t } = useTranslation() |
no test coverage detected