lib/format.ts gains shortTime(value, zone) and becomes the home of the single duration() formatter (moved from timeline-event.ts, which re-exports it so the stage rail and duration.test.ts are unchanged). LogTable's time column, audit's From/To chips and chat session titles now format in the zone chosen under Appearance instead of the browser's. StepNode, schedule runDuration, labels formatMs and ChatToolCall all delegate to duration(), removing the "12ms" vs "12 ms" vs "under 1 s" split.
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
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<string, Intl.DateTimeFormat>();
|
|
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";
|
|
}
|