mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:41:23 +00:00
Centralize date/time formatting utilities (#11831)
This commit is contained in:
@@ -8,7 +8,7 @@ import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { resolveChannelDefaultAccountId } from "../../channels/plugins/helpers.js";
|
||||
import { listChannelPlugins } from "../../channels/plugins/index.js";
|
||||
import { sha256HexPrefix } from "../../logging/redact-identifier.js";
|
||||
import { formatAge } from "./format.js";
|
||||
import { formatTimeAgo } from "./format.js";
|
||||
|
||||
export type ChannelRow = {
|
||||
id: ChannelId;
|
||||
@@ -436,7 +436,7 @@ export async function buildChannelsTable(
|
||||
extra.push(link.selfE164);
|
||||
}
|
||||
if (link.linked && link.authAgeMs != null && link.authAgeMs >= 0) {
|
||||
extra.push(`auth ${formatAge(link.authAgeMs)}`);
|
||||
extra.push(`auth ${formatTimeAgo(link.authAgeMs)}`);
|
||||
}
|
||||
if (accounts.length > 1 || plugin.meta.forceAccountBinding) {
|
||||
extra.push(`accounts ${accounts.length || 1}`);
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
type RestartSentinelPayload,
|
||||
summarizeRestartSentinel,
|
||||
} from "../../infra/restart-sentinel.js";
|
||||
import { formatAge, redactSecrets } from "./format.js";
|
||||
import { formatTimeAgo, redactSecrets } from "./format.js";
|
||||
import { readFileTailLines, summarizeLogTail } from "./gateway.js";
|
||||
|
||||
type ConfigIssueLike = { path: string; message: string };
|
||||
@@ -106,7 +106,7 @@ export async function appendStatusAllDiagnosis(params: {
|
||||
if (params.sentinel?.payload) {
|
||||
emitCheck("Restart sentinel present", "warn");
|
||||
lines.push(
|
||||
` ${muted(`${summarizeRestartSentinel(params.sentinel.payload)} · ${formatAge(Date.now() - params.sentinel.payload.ts)}`)}`,
|
||||
` ${muted(`${summarizeRestartSentinel(params.sentinel.payload)} · ${formatTimeAgo(Date.now() - params.sentinel.payload.ts)}`)}`,
|
||||
);
|
||||
} else {
|
||||
emitCheck("Restart sentinel: none", "ok");
|
||||
|
||||
@@ -1,31 +1,5 @@
|
||||
export const formatAge = (ms: number | null | undefined) => {
|
||||
if (!ms || ms < 0) {
|
||||
return "unknown";
|
||||
}
|
||||
const minutes = Math.round(ms / 60_000);
|
||||
if (minutes < 1) {
|
||||
return "just now";
|
||||
}
|
||||
if (minutes < 60) {
|
||||
return `${minutes}m ago`;
|
||||
}
|
||||
const hours = Math.round(minutes / 60);
|
||||
if (hours < 48) {
|
||||
return `${hours}h ago`;
|
||||
}
|
||||
const days = Math.round(hours / 24);
|
||||
return `${days}d ago`;
|
||||
};
|
||||
|
||||
export const formatDuration = (ms: number | null | undefined) => {
|
||||
if (ms == null || !Number.isFinite(ms)) {
|
||||
return "unknown";
|
||||
}
|
||||
if (ms < 1000) {
|
||||
return `${Math.round(ms)}ms`;
|
||||
}
|
||||
return `${(ms / 1000).toFixed(1)}s`;
|
||||
};
|
||||
export { formatTimeAgo } from "../../infra/format-time/format-relative.ts";
|
||||
export { formatDurationPrecise } from "../../infra/format-time/format-duration.ts";
|
||||
|
||||
export function formatGatewayAuthUsed(
|
||||
auth: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ProgressReporter } from "../../cli/progress.js";
|
||||
import { renderTable } from "../../terminal/table.js";
|
||||
import { isRich, theme } from "../../terminal/theme.js";
|
||||
import { appendStatusAllDiagnosis } from "./diagnosis.js";
|
||||
import { formatAge } from "./format.js";
|
||||
import { formatTimeAgo } from "./format.js";
|
||||
|
||||
type OverviewRow = { Item: string; Value: string };
|
||||
|
||||
@@ -128,7 +128,7 @@ export async function buildStatusAllReportLines(params: {
|
||||
? ok("OK")
|
||||
: "unknown",
|
||||
Sessions: String(a.sessionsCount),
|
||||
Active: a.lastActiveAgeMs != null ? formatAge(a.lastActiveAgeMs) : "unknown",
|
||||
Active: a.lastActiveAgeMs != null ? formatTimeAgo(a.lastActiveAgeMs) : "unknown",
|
||||
Store: a.sessionsPath,
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user