From 0dc5bf9a9b232e373d3fbc228b5e4a47c080b9e7 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 6 Nov 2026 22:21:45 +1100 Subject: [PATCH] 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. --- ui/src/audit/audit.ts | 5 ++++- ui/src/base/LogTable.vue | 8 ++++++-- ui/src/chat/ChatToolCall.vue | 7 ++----- ui/src/chat/session.ts | 28 +++++++++++++++++++++------- ui/src/lib/format.ts | 26 ++++++++++++++++++++++++++ ui/src/lib/log.ts | 6 ------ ui/src/schedules/schedule.ts | 12 +++--------- ui/src/tasks/timeline-event.ts | 25 ++++++------------------- ui/src/workflows/StepNode.vue | 8 ++------ ui/src/workflows/labels.ts | 7 +++---- 10 files changed, 73 insertions(+), 59 deletions(-) diff --git a/ui/src/audit/audit.ts b/ui/src/audit/audit.ts index 724a05f7a..24bdaea1c 100644 --- a/ui/src/audit/audit.ts +++ b/ui/src/audit/audit.ts @@ -2,6 +2,8 @@ import type { LocationQuery } from "vue-router"; import type { QueryParams } from "@/lib/api"; import { formatValue, type Change } from "@/lib/changes"; +import { exactTime } from "../lib/format.ts"; +import { useAppearanceStore } from "../stores/appearance"; /** One actor as the audit feed reports it. */ export interface AuditActor { @@ -296,7 +298,8 @@ function settingsKindLabel(options: SettingsKind[], value: string): string { function localTime(value: string): string { const date = new Date(value); - return Number.isNaN(date.getTime()) ? value : date.toLocaleString(); + // In the zone chosen under Appearance, like Timestamp, not the browser's. + return Number.isNaN(date.getTime()) ? value : exactTime(date, useAppearanceStore().timeZone); } /** The advanced and deep-link filters as removable chips. */ diff --git a/ui/src/base/LogTable.vue b/ui/src/base/LogTable.vue index 8adb62d9b..e03c75996 100644 --- a/ui/src/base/LogTable.vue +++ b/ui/src/base/LogTable.vue @@ -3,7 +3,11 @@ import { DataTable, type DataTableColumn } from "@/components/ui/data-table"; import { computed } from "vue"; import { MetadataList } from "@/components/ui/metadata-list"; -import { fmtValue, LEVEL_COLOR, levelKind, rowClass, shortTime, type LogEntry } from "@/lib/log"; +import { fmtValue, LEVEL_COLOR, levelKind, rowClass, type LogEntry } from "@/lib/log"; +import { shortTime } from "@/lib/format"; +import { useAppearanceStore } from "@/stores/appearance"; + +const appearance = useAppearanceStore(); /** * Log entries as a table: time, level, stage, service and message, with an @@ -57,7 +61,7 @@ const details = (entry: LogEntry) => :initial-sort="newestFirst ? { id: 'time', desc: true } : undefined" sticky-header > - + diff --git a/ui/src/chat/ChatToolCall.vue b/ui/src/chat/ChatToolCall.vue index 033495376..c5ffeede3 100644 --- a/ui/src/chat/ChatToolCall.vue +++ b/ui/src/chat/ChatToolCall.vue @@ -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(() => { diff --git a/ui/src/chat/session.ts b/ui/src/chat/session.ts index f01ee2b91..374268d93 100644 --- a/ui/src/chat/session.ts +++ b/ui/src/chat/session.ts @@ -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(); +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"; } diff --git a/ui/src/lib/format.ts b/ui/src/lib/format.ts index 757d17784..1b29e213c 100644 --- a/ui/src/lib/format.ts +++ b/ui/src/lib/format.ts @@ -38,3 +38,29 @@ export function compact(n: number | null | undefined): string { export function exactTime(value: Date, zone: string): string { return value.toLocaleString(undefined, zone ? { timeZone: zone, timeZoneName: "short" } : undefined); } + +/** A time of day in zone, or in the browser's zone when zone is empty: "14:03:22". */ +export function shortTime(value: string | number | Date, zone = ""): string { + const d = value instanceof Date ? value : new Date(value); + if (Number.isNaN(d.getTime())) return "--:--:--"; + return d.toLocaleTimeString(undefined, { hour12: false, ...(zone ? { timeZone: zone } : {}) }); +} + +/** The one duration formatter every view uses: "under 1 s", "41 s", "41 min 41 s", + * "2 h 3 min". Empty string when there is no duration. */ +export function duration(milliseconds: unknown): string { + const ms = Number(milliseconds); + if (!Number.isFinite(ms) || ms < 0) return ""; + if (ms < 1000) return "under 1 s"; + const seconds = ms / 1000; + // Under 60s: 1 dp when seconds < 10, 0 dp otherwise (40.6 s, but 41 s). + if (seconds < 60) return `${seconds.toFixed(seconds < 10 ? 1 : 0)} s`; + const roundedSeconds = Math.round(seconds); + const minutes = Math.floor(roundedSeconds / 60); + const remSec = roundedSeconds % 60; + if (minutes < 60) + return remSec === 0 ? `${minutes} min` : `${minutes} min ${remSec} s`; + const hours = Math.floor(minutes / 60); + const remMin = minutes - hours * 60; + return remMin === 0 ? `${hours} h` : `${hours} h ${remMin} min`; +} diff --git a/ui/src/lib/log.ts b/ui/src/lib/log.ts index d71f2236c..534500f5f 100644 --- a/ui/src/lib/log.ts +++ b/ui/src/lib/log.ts @@ -61,9 +61,3 @@ export function fmtValue(v: unknown): string { if (v == null) return ""; return typeof v === "object" ? JSON.stringify(v) : String(v); } - -export function shortTime(value: string | number | Date): string { - const d = value instanceof Date ? value : new Date(value); - if (Number.isNaN(d.getTime())) return "--:--:--"; - return d.toTimeString().slice(0, 8); -} diff --git a/ui/src/schedules/schedule.ts b/ui/src/schedules/schedule.ts index d265b941d..8adbefcd3 100644 --- a/ui/src/schedules/schedule.ts +++ b/ui/src/schedules/schedule.ts @@ -4,6 +4,7 @@ */ import { parseGoDuration } from "@/components/ui/duration-input"; +import { duration } from "../lib/format.ts"; /** What a schedule belongs to; name is resolved by the server. */ export interface ScheduleOwner { @@ -115,17 +116,10 @@ export function timingWords(timing: ScheduleTiming, zone: string, format: (at: s } } -/** A run's duration as "1m 4s", or "" while it has not finished. */ +/** A run's duration in the one shared format, or "" while it has not finished. */ export function runDuration(run: ScheduleRun | null | undefined): string { if (!run?.started || !run.finished) return ""; - const ms = Date.parse(run.finished) - Date.parse(run.started); - if (!Number.isFinite(ms) || ms < 0) return ""; - if (ms < 1000) return `${ms}ms`; - const secs = Math.round(ms / 1000); - if (secs < 60) return `${secs}s`; - const mins = Math.floor(secs / 60); - if (mins < 60) return `${mins}m ${secs % 60}s`; - return `${Math.floor(mins / 60)}h ${mins % 60}m`; + return duration(Date.parse(run.finished) - Date.parse(run.started)); } // The zone's offset from UTC at instant, in ms. Empty zone is the browser's. diff --git a/ui/src/tasks/timeline-event.ts b/ui/src/tasks/timeline-event.ts index ed1ec29ce..54de26428 100644 --- a/ui/src/tasks/timeline-event.ts +++ b/ui/src/tasks/timeline-event.ts @@ -5,33 +5,20 @@ * read them -- the timeline row and the stage rail's agent reports -- and a * second copy would eventually disagree with this one. */ +import { duration } from "../lib/format.ts"; + import type { TaskEvent } from "./task-run"; +// The one duration formatter lives in lib/format; re-exported so the stage +// rail renders a duration exactly the way the timeline does. +export { duration }; + function words(value: unknown): string { return String(value || "event") .replaceAll("_", " ") .replace(/\b\w/g, (letter) => letter.toUpperCase()); } -/** Exported so the stage rail renders a duration exactly the way the timeline - * does; a second formatter would eventually disagree with this one. */ -export function duration(milliseconds: unknown): string { - const ms = Number(milliseconds); - if (!Number.isFinite(ms) || ms < 0) return ""; - if (ms < 1000) return "under 1 s"; - const seconds = ms / 1000; - // Under 60s: 1 dp when seconds < 10, 0 dp otherwise (40.6 s, but 41 s). - if (seconds < 60) return `${seconds.toFixed(seconds < 10 ? 1 : 0)} s`; - const roundedSeconds = Math.round(seconds); - const minutes = Math.floor(roundedSeconds / 60); - const remSec = roundedSeconds % 60; - if (minutes < 60) - return remSec === 0 ? `${minutes} min` : `${minutes} min ${remSec} s`; - const hours = Math.floor(minutes / 60); - const remMin = minutes - hours * 60; - return remMin === 0 ? `${hours} h` : `${hours} h ${remMin} min`; -} - function count(value: unknown): string { const n = Number(value); // Render only for positive counts; zero is treated as "no metric diff --git a/ui/src/workflows/StepNode.vue b/ui/src/workflows/StepNode.vue index ce41f7b38..0e2b94726 100644 --- a/ui/src/workflows/StepNode.vue +++ b/ui/src/workflows/StepNode.vue @@ -7,6 +7,7 @@ import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { Input } from "@/components/ui/input"; +import { duration } from "@/lib/format"; import { stepIcon } from "./step-icons"; import { stepTitle, type StepNodeData } from "./workflow-graph"; @@ -72,12 +73,7 @@ const badge = computed(() => { }); const number = computed(() => (props.data.step ? `${Number(props.data.step)}.` : "")); -function duration(ms?: number): string { - if (ms === undefined) return ""; - if (ms < 1000) return `${ms} ms`; - const seconds = Math.round(ms / 1000); - return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`; -} + const card = ref(null); let observer: ResizeObserver | undefined; diff --git a/ui/src/workflows/labels.ts b/ui/src/workflows/labels.ts index b8d804dd8..487ec6a14 100644 --- a/ui/src/workflows/labels.ts +++ b/ui/src/workflows/labels.ts @@ -1,5 +1,7 @@ /** Naming and numbers shared by the workflow tables. */ +import { duration } from "../lib/format.ts"; + const WORKFLOW_LABELS: Record = { implement: "Implement", tdd: "TDD", @@ -27,8 +29,5 @@ export function pct( export function formatMs(ms: number | undefined | null): string { if (!ms) return "–"; - if (ms < 1000) return `${ms} ms`; - const secs = ms / 1000; - if (secs < 60) return `${secs.toFixed(1)} s`; - return `${(secs / 60).toFixed(1)} min`; + return duration(ms); }