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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user