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
@@ -2,6 +2,8 @@ import type { LocationQuery } from "vue-router";
|
|||||||
|
|
||||||
import type { QueryParams } from "@/lib/api";
|
import type { QueryParams } from "@/lib/api";
|
||||||
import { formatValue, type Change } from "@/lib/changes";
|
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. */
|
/** One actor as the audit feed reports it. */
|
||||||
export interface AuditActor {
|
export interface AuditActor {
|
||||||
@@ -296,7 +298,8 @@ function settingsKindLabel(options: SettingsKind[], value: string): string {
|
|||||||
|
|
||||||
function localTime(value: string): string {
|
function localTime(value: string): string {
|
||||||
const date = new Date(value);
|
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. */
|
/** The advanced and deep-link filters as removable chips. */
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
|||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
|
|
||||||
import { MetadataList } from "@/components/ui/metadata-list";
|
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
|
* 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"
|
:initial-sort="newestFirst ? { id: 'time', desc: true } : undefined"
|
||||||
sticky-header
|
sticky-header
|
||||||
>
|
>
|
||||||
<template #cell-time="{ row }"><span class="font-mono text-xs text-fg-subtle">{{ shortTime(row.time) }}</span></template>
|
<template #cell-time="{ row }"><span class="font-mono text-xs text-fg-subtle">{{ shortTime(row.time, appearance.timeZone) }}</span></template>
|
||||||
<template #cell-level="{ row }">
|
<template #cell-level="{ row }">
|
||||||
<span class="text-micro font-semibold tracking-[0.04em]" :class="LEVEL_COLOR[levelKind(row.level)]">{{ (row.level || "info").toUpperCase() }}</span>
|
<span class="text-micro font-semibold tracking-[0.04em]" :class="LEVEL_COLOR[levelKind(row.level)]">{{ (row.level || "info").toUpperCase() }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { CircleCheck, CircleX } from "@lucide/vue";
|
|||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
|
|
||||||
import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block";
|
import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block";
|
||||||
|
import { duration as formatDuration } from "@/lib/format";
|
||||||
import {
|
import {
|
||||||
TraceCollapsible,
|
TraceCollapsible,
|
||||||
TraceCollapsibleContent,
|
TraceCollapsibleContent,
|
||||||
@@ -52,11 +53,7 @@ const outcome = computed(
|
|||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
const running = computed(() => !outcome.value && !failed.value && !!props.streaming);
|
const running = computed(() => !outcome.value && !failed.value && !!props.streaming);
|
||||||
const duration = computed(() => {
|
const duration = computed(() => formatDuration(props.tool.duration_ms));
|
||||||
const ms = props.tool.duration_ms;
|
|
||||||
if (!ms) return "";
|
|
||||||
return ms < 1000 ? `${ms}ms` : `${(ms / 1000).toFixed(ms < 10000 ? 1 : 0)}s`;
|
|
||||||
});
|
|
||||||
// The row shows the call's main value, as "git diff --stat" rather than its
|
// 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.
|
// JSON: the first string argument, else its arguments as key: value pairs.
|
||||||
const argument = computed(() => {
|
const argument = computed(() => {
|
||||||
|
|||||||
+21
-7
@@ -1,16 +1,30 @@
|
|||||||
|
import { useAppearanceStore } from "../stores/appearance";
|
||||||
|
|
||||||
import type { ChatSession } from "./state";
|
import type { ChatSession } from "./state";
|
||||||
|
|
||||||
const started = new Intl.DateTimeFormat(undefined, {
|
// One formatter per zone, cached: the zone chosen under Appearance is applied
|
||||||
month: "short",
|
// here like Timestamp applies it, not the browser's zone.
|
||||||
day: "numeric",
|
const startedCache = new Map<string, Intl.DateTimeFormat>();
|
||||||
hour: "numeric",
|
function started(zone: string): Intl.DateTimeFormat {
|
||||||
minute: "2-digit",
|
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
|
// An untitled conversation is named by when it began, which tells two apart
|
||||||
// where a raw id cannot.
|
// where a raw id cannot.
|
||||||
export function sessionTitle(session: ChatSession): string {
|
export function sessionTitle(session: ChatSession): string {
|
||||||
const named = session.title || session.branch_name;
|
const named = session.title || session.branch_name;
|
||||||
if (named) return named;
|
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";
|
||||||
}
|
}
|
||||||
@@ -38,3 +38,29 @@ export function compact(n: number | null | undefined): string {
|
|||||||
export function exactTime(value: Date, zone: string): string {
|
export function exactTime(value: Date, zone: string): string {
|
||||||
return value.toLocaleString(undefined, zone ? { timeZone: zone, timeZoneName: "short" } : undefined);
|
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`;
|
||||||
|
}
|
||||||
@@ -61,9 +61,3 @@ export function fmtValue(v: unknown): string {
|
|||||||
if (v == null) return "";
|
if (v == null) return "";
|
||||||
return typeof v === "object" ? JSON.stringify(v) : String(v);
|
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);
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { parseGoDuration } from "@/components/ui/duration-input";
|
import { parseGoDuration } from "@/components/ui/duration-input";
|
||||||
|
import { duration } from "../lib/format.ts";
|
||||||
|
|
||||||
/** What a schedule belongs to; name is resolved by the server. */
|
/** What a schedule belongs to; name is resolved by the server. */
|
||||||
export interface ScheduleOwner {
|
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 {
|
export function runDuration(run: ScheduleRun | null | undefined): string {
|
||||||
if (!run?.started || !run.finished) return "";
|
if (!run?.started || !run.finished) return "";
|
||||||
const ms = Date.parse(run.finished) - Date.parse(run.started);
|
return duration(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`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The zone's offset from UTC at instant, in ms. Empty zone is the browser's.
|
// The zone's offset from UTC at instant, in ms. Empty zone is the browser's.
|
||||||
|
|||||||
@@ -5,33 +5,20 @@
|
|||||||
* read them -- the timeline row and the stage rail's agent reports -- and a
|
* read them -- the timeline row and the stage rail's agent reports -- and a
|
||||||
* second copy would eventually disagree with this one.
|
* second copy would eventually disagree with this one.
|
||||||
*/
|
*/
|
||||||
|
import { duration } from "../lib/format.ts";
|
||||||
|
|
||||||
import type { TaskEvent } from "./task-run";
|
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 {
|
function words(value: unknown): string {
|
||||||
return String(value || "event")
|
return String(value || "event")
|
||||||
.replaceAll("_", " ")
|
.replaceAll("_", " ")
|
||||||
.replace(/\b\w/g, (letter) => letter.toUpperCase());
|
.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 {
|
function count(value: unknown): string {
|
||||||
const n = Number(value);
|
const n = Number(value);
|
||||||
// Render only for positive counts; zero is treated as "no metric
|
// Render only for positive counts; zero is treated as "no metric
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Badge } from "@/components/ui/badge";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { duration } from "@/lib/format";
|
||||||
import { stepIcon } from "./step-icons";
|
import { stepIcon } from "./step-icons";
|
||||||
import { stepTitle, type StepNodeData } from "./workflow-graph";
|
import { stepTitle, type StepNodeData } from "./workflow-graph";
|
||||||
|
|
||||||
@@ -72,12 +73,7 @@ const badge = computed(() => {
|
|||||||
});
|
});
|
||||||
const number = computed(() => (props.data.step ? `${Number(props.data.step)}.` : ""));
|
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<HTMLElement | null>(null);
|
const card = ref<HTMLElement | null>(null);
|
||||||
let observer: ResizeObserver | undefined;
|
let observer: ResizeObserver | undefined;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
/** Naming and numbers shared by the workflow tables. */
|
/** Naming and numbers shared by the workflow tables. */
|
||||||
|
|
||||||
|
import { duration } from "../lib/format.ts";
|
||||||
|
|
||||||
const WORKFLOW_LABELS: Record<string, string> = {
|
const WORKFLOW_LABELS: Record<string, string> = {
|
||||||
implement: "Implement",
|
implement: "Implement",
|
||||||
tdd: "TDD",
|
tdd: "TDD",
|
||||||
@@ -27,8 +29,5 @@ export function pct(
|
|||||||
|
|
||||||
export function formatMs(ms: number | undefined | null): string {
|
export function formatMs(ms: number | undefined | null): string {
|
||||||
if (!ms) return "–";
|
if (!ms) return "–";
|
||||||
if (ms < 1000) return `${ms} ms`;
|
return duration(ms);
|
||||||
const secs = ms / 1000;
|
|
||||||
if (secs < 60) return `${secs.toFixed(1)} s`;
|
|
||||||
return `${(secs / 60).toFixed(1)} min`;
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user