fix(ui): times honour the Appearance zone, one duration formatter everywhere (#1761)
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.
This commit is contained in:
10 files changed
+73
-59
No files matched your search
@@ -4,6 +4,7 @@ import { CircleCheck, CircleX } from "@lucide/vue";
|
||||
import { computed } from "vue";
|
||||
|
||||
import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block";
|
||||
import { duration as formatDuration } from "@/lib/format";
|
||||
import {
|
||||
TraceCollapsible,
|
||||
TraceCollapsibleContent,
|
||||
@@ -52,11 +53,7 @@ const outcome = computed(
|
||||
"",
|
||||
);
|
||||
const running = computed(() => !outcome.value && !failed.value && !!props.streaming);
|
||||
const duration = computed(() => {
|
||||
const ms = props.tool.duration_ms;
|
||||
if (!ms) return "";
|
||||
return ms < 1000 ? `${ms}ms` : `${(ms / 1000).toFixed(ms < 10000 ? 1 : 0)}s`;
|
||||
});
|
||||
const duration = computed(() => formatDuration(props.tool.duration_ms));
|
||||
// The row shows the call's main value, as "git diff --stat" rather than its
|
||||
// JSON: the first string argument, else its arguments as key: value pairs.
|
||||
const argument = computed(() => {
|
||||
|
||||
+21
-7
@@ -1,16 +1,30 @@
|
||||
import { useAppearanceStore } from "../stores/appearance";
|
||||
|
||||
import type { ChatSession } from "./state";
|
||||
|
||||
const started = new Intl.DateTimeFormat(undefined, {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
});
|
||||
// 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.format(new Date(session.created_at)) : "New chat";
|
||||
return session.created_at
|
||||
? started(useAppearanceStore().timeZone).format(new Date(session.created_at))
|
||||
: "New chat";
|
||||
}
|
||||
Reference in new issue
Block a user