import { useAppearanceStore } from "../stores/appearance"; import type { ChatSession } from "./state"; // One formatter per zone, cached: the zone chosen under Appearance is applied // here like Timestamp applies it, not the browser's zone. const startedCache = new Map(); function started(zone: string): Intl.DateTimeFormat { const cached = startedCache.get(zone); if (cached) return cached; const format = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit", ...(zone ? { timeZone: zone } : {}), }); startedCache.set(zone, format); return format; } // An untitled conversation is named by when it began, which tells two apart // where a raw id cannot. export function sessionTitle(session: ChatSession): string { const named = session.title || session.branch_name; if (named) return named; return session.created_at ? started(useAppearanceStore().timeZone).format(new Date(session.created_at)) : "New chat"; }