Centralize date/time formatting utilities (#11831)
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
} from "../commands/status.update.js";
|
||||
import { readConfigFileSnapshot, writeConfigFile } from "../config/config.js";
|
||||
import { resolveStateDir } from "../config/paths.js";
|
||||
import { formatDurationPrecise } from "../infra/format-time/format-duration.ts";
|
||||
import { resolveOpenClawPackageRoot } from "../infra/openclaw-root.js";
|
||||
import { trimLogTail } from "../infra/restart-sentinel.js";
|
||||
import { parseSemver } from "../infra/runtime-guard.js";
|
||||
@@ -575,7 +576,7 @@ function createUpdateProgress(enabled: boolean): ProgressController {
|
||||
}
|
||||
|
||||
const label = getStepLabel(step);
|
||||
const duration = theme.muted(`(${formatDuration(step.durationMs)})`);
|
||||
const duration = theme.muted(`(${formatDurationPrecise(step.durationMs)})`);
|
||||
const icon = step.exitCode === 0 ? theme.success("\u2713") : theme.error("\u2717");
|
||||
|
||||
currentSpinner.stop(`${icon} ${label} ${duration}`);
|
||||
@@ -603,14 +604,6 @@ function createUpdateProgress(enabled: boolean): ProgressController {
|
||||
};
|
||||
}
|
||||
|
||||
function formatDuration(ms: number): string {
|
||||
if (ms < 1000) {
|
||||
return `${ms}ms`;
|
||||
}
|
||||
const seconds = (ms / 1000).toFixed(1);
|
||||
return `${seconds}s`;
|
||||
}
|
||||
|
||||
function formatStepStatus(exitCode: number | null): string {
|
||||
if (exitCode === 0) {
|
||||
return theme.success("\u2713");
|
||||
@@ -668,7 +661,7 @@ function printResult(result: UpdateRunResult, opts: PrintResultOptions) {
|
||||
defaultRuntime.log(theme.heading("Steps:"));
|
||||
for (const step of result.steps) {
|
||||
const status = formatStepStatus(step.exitCode);
|
||||
const duration = theme.muted(`(${formatDuration(step.durationMs)})`);
|
||||
const duration = theme.muted(`(${formatDurationPrecise(step.durationMs)})`);
|
||||
defaultRuntime.log(` ${status} ${step.name} ${duration}`);
|
||||
|
||||
if (step.exitCode !== 0 && step.stderrTail) {
|
||||
@@ -683,7 +676,7 @@ function printResult(result: UpdateRunResult, opts: PrintResultOptions) {
|
||||
}
|
||||
|
||||
defaultRuntime.log("");
|
||||
defaultRuntime.log(`Total time: ${theme.muted(formatDuration(result.durationMs))}`);
|
||||
defaultRuntime.log(`Total time: ${theme.muted(formatDurationPrecise(result.durationMs))}`);
|
||||
}
|
||||
|
||||
export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user