Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix: roll long durations over into days instead of 221h (#19965)

Arvin Xu807ac86f4b0c
diff --git a/apps/server/src/services/bot/platforms/utils.test.ts b/apps/server/src/services/bot/platforms/utils.test.ts
index 2796f466f5f..dc50fd7d6b2 100644
--- a/apps/server/src/services/bot/platforms/utils.test.ts
+++ b/apps/server/src/services/bot/platforms/utils.test.ts
@@ -58,8 +58,13 @@ describe('formatDuration', () => {
});
it('should format minutes and seconds', () => {
- expect(formatDuration(65_000)).toBe('1m5s');
- expect(formatDuration(120_000)).toBe('2m0s');
+ expect(formatDuration(65_000)).toBe('1m 5s');
+ expect(formatDuration(120_000)).toBe('2m 0s');
+ });
+
+ it('should roll long runs up into hours and days', () => {
+ expect(formatDuration(3_723_000)).toBe('1h 2m');
+ expect(formatDuration(90_000_000)).toBe('1d 1h 0m');
});
});
diff --git a/apps/server/src/services/bot/platforms/utils.ts b/apps/server/src/services/bot/platforms/utils.ts
index 6a0cf799456..388340b121f 100644
--- a/apps/server/src/services/bot/platforms/utils.ts
+++ b/apps/server/src/services/bot/platforms/utils.ts
@@ -1,5 +1,5 @@
import { DEFAULT_BOT_DEBOUNCE_MS } from '@lobechat/const';
-import { merge } from '@lobechat/utils';
+import { formatDuration as formatDurationMs, merge } from '@lobechat/utils';
import type {
BotProviderConfig,
@@ -259,12 +259,7 @@ export function formatTokens(tokens: number): string {
}
export function formatDuration(ms: number): string {
- const totalSeconds = Math.floor(ms / 1000);
- const minutes = Math.floor(totalSeconds / 60);
- const seconds = totalSeconds % 60;
-
- if (minutes > 0) return `${minutes}m${seconds}s`;
- return `${seconds}s`;
+ return formatDurationMs(ms);
}
/**
diff --git a/packages/utils/src/timing.test.ts b/packages/utils/src/timing.test.ts
index 55d8c9b894a..bf496eb49ec 100644
--- a/packages/utils/src/timing.test.ts
+++ b/packages/utils/src/timing.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import {
createTimingHelpers,
+ formatDuration,
formatElapsedClockTime,
markTimingSinkStageDone,
markTimingStageDone,
@@ -23,11 +24,57 @@ describe('timing utilities', () => {
expect(formatElapsedClockTime(3_661_000)).toBe('1:01:01');
});
+ it('prefixes days once elapsed time passes 24 hours', () => {
+ expect(formatElapsedClockTime(86_400_000 + 3_661_000)).toBe('1d 01:01:01');
+ });
+
it('clamps negative elapsed time to zero', () => {
expect(formatElapsedClockTime(-1_000)).toBe('00:00');
});
});
+ describe('formatDuration', () => {
+ const s = 1000;
+ const m = 60 * s;
+ const h = 60 * m;
+ const d = 24 * h;
+
+ it('shows seconds below one hour and drops them above it', () => {
+ expect(formatDuration(0)).toBe('0s');
+ expect(formatDuration(42 * s)).toBe('42s');
+ expect(formatDuration(3 * m + 7 * s)).toBe('3m 7s');
+ expect(formatDuration(23 * h + 59 * m + 59 * s)).toBe('23h 59m');
+ });
+
+ it('rolls hours over into days past 24 hours', () => {
+ expect(formatDuration(d)).toBe('1d 0h 0m');
+ expect(formatDuration(d + 21 * h + 23 * m)).toBe('1d 21h 23m');
+ expect(formatDuration(221 * h + 29 * m)).toBe('9d 5h 29m');
+ });
+
+ it('honours an explicit smallest unit', () => {
+ expect(formatDuration(30 * s, { minUnit: 'm' })).toBe('0m');
+ expect(formatDuration(h + 2 * m + 3 * s, { minUnit: 's' })).toBe('1h 2m 3s');
+ expect(formatDuration(d + 2 * m, { minUnit: 's' })).toBe('1d 0h 2m 0s');
+ });
+
+ it('pads trailing units when asked', () => {
+ expect(formatDuration(3 * m + 5 * s, { pad: true })).toBe('3m 05s');
+ expect(formatDuration(d + 5 * h + 4 * m, { pad: true })).toBe('1d 05h 04m');
+ });
+
+ it('trims zero trailing units when asked', () => {
+ expect(formatDuration(3 * m, { trimZero: true })).toBe('3m');
+ expect(formatDuration(h, { trimZero: true })).toBe('1h');
+ expect(formatDuration(d + 3 * h, { trimZero: true })).toBe('1d 3h');
+ expect(formatDuration(d + 3 * m, { trimZero: true })).toBe('1d 0h 3m');
+ });
+
+ it('clamps negative durations to zero', () => {
+ expect(formatDuration(-5 * s)).toBe('0s');
+ });
+ });
+
describe('markTimingStageDone', () => {
it('should emit a done marker with zero stage duration', () => {
const logger = vi.fn<TimingLogger>();
diff --git a/packages/utils/src/timing.ts b/packages/utils/src/timing.ts
index fe6f75ab8fa..ff9d563691d 100644
--- a/packages/utils/src/timing.ts
+++ b/packages/utils/src/timing.ts
@@ -29,15 +29,65 @@ export const getDurationMs = (startedAt: number) => Date.now() - startedAt;
export const formatElapsedClockTime = (ms: number) => {
const normalizedMs = Math.max(0, ms);
const totalSeconds = Math.floor(normalizedMs / 1000);
- const hours = Math.floor(totalSeconds / 3600);
+ const days = Math.floor(totalSeconds / 86_400);
+ const hours = Math.floor((totalSeconds % 86_400) / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
const mm = String(minutes).padStart(2, '0');
const ss = String(seconds).padStart(2, '0');
+ if (days > 0) return `${days}d ${String(hours).padStart(2, '0')}:${mm}:${ss}`;
return hours > 0 ? `${hours}:${mm}:${ss}` : `${mm}:${ss}`;
};
+const DURATION_UNITS = [
+ { ms: 86_400_000, suffix: 'd' },
+ { ms: 3_600_000, suffix: 'h' },
+ { ms: 60_000, suffix: 'm' },
+ { ms: 1000, suffix: 's' },
+] as const;
+
+export interface FormatDurationOptions {
+ /**
+ * Smallest unit to print. By default seconds are shown below one hour and
+ * dropped above it, where they only add noise.
+ */
+ minUnit?: 'm' | 's';
+ /** Zero-pad every unit after the first (`1h 04m`), keeping live timers from jittering. */
+ pad?: boolean;
+ /** Drop zero-valued trailing units (`1h` instead of `1h 0m`). */
+ trimZero?: boolean;
+}
+
+/**
+ * Compact unit duration: `42s` Β· `3m 7s` Β· `1h 23m` Β· `1d 21h 23m`. Hours roll over
+ * into days, so a long-running span never reads as `221h 29m`. The input is floored
+ * to the smallest printed unit; round it first when the caller wants rounding.
+ */
+export const formatDuration = (ms: number, options: FormatDurationOptions = {}): string => {
+ const { minUnit, pad, trimZero } = options;
+ const total = Math.max(0, ms);
+ const lastSuffix = minUnit ?? (total < 3_600_000 ? 's' : 'm');
+ const lastIndex = DURATION_UNITS.findIndex((unit) => unit.suffix === lastSuffix);
+ const largestIndex = DURATION_UNITS.findIndex((unit) => total >= unit.ms);
+ const firstIndex = largestIndex === -1 ? lastIndex : Math.min(largestIndex, lastIndex);
+
+ let remaining = total;
+ const parts = DURATION_UNITS.slice(firstIndex, lastIndex + 1).map((unit, index) => {
+ const value = Math.floor(remaining / unit.ms);
+ remaining -= value * unit.ms;
+ return {
+ suffix: unit.suffix,
+ text: pad && index > 0 ? String(value).padStart(2, '0') : String(value),
+ value,
+ };
+ });
+
+ while (trimZero && parts.length > 1 && parts.at(-1)!.value === 0) parts.pop();
+
+ return parts.map((part) => `${part.text}${part.suffix}`).join(' ');
+};
+
export const createTimingRequestId = () =>
globalThis.crypto?.randomUUID?.() ??
`${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
diff --git a/src/features/AgentGoals/ProcessControl/useElapsed.ts b/src/features/AgentGoals/ProcessControl/useElapsed.ts
index 4121605c1d1..888c9540952 100644
--- a/src/features/AgentGoals/ProcessControl/useElapsed.ts
+++ b/src/features/AgentGoals/ProcessControl/useElapsed.ts
@@ -1,14 +1,8 @@
+import { formatDuration } from '@lobechat/utils';
import { useEffect, useState } from 'react';
-/** Same digit-unit shape the Task page's run cards use: `12s` Β· `3m 12s` Β· `1h 04m`. */
-export const formatElapsed = (ms: number): string => {
- const seconds = Math.max(0, Math.floor(ms / 1000));
- if (seconds < 60) return `${seconds}s`;
- const minutes = Math.floor(seconds / 60);
- if (minutes < 60) return `${minutes}m ${String(seconds % 60).padStart(2, '0')}s`;
- const hours = Math.floor(minutes / 60);
- return `${hours}h ${String(minutes % 60).padStart(2, '0')}m`;
-};
+/** Same digit-unit shape the Task page's run cards use: `12s` Β· `3m 12s` Β· `1h 04m` Β· `1d 05h 04m`. */
+export const formatElapsed = (ms: number): string => formatDuration(ms, { pad: true });
/** Live "how long has this been running" label; idle when there is nothing running. */
export const useElapsed = (startedAt?: Date): string => {
diff --git a/src/features/AgentGoals/goalPresentation.ts b/src/features/AgentGoals/goalPresentation.ts
index b1445a6436c..5e432cfa19d 100644
--- a/src/features/AgentGoals/goalPresentation.ts
+++ b/src/features/AgentGoals/goalPresentation.ts
@@ -1,5 +1,6 @@
import type { GoalStatus } from '@lobechat/const/goal';
import type { GoalConfig, GoalSpend, TaskStatus } from '@lobechat/types';
+import { formatDuration } from '@lobechat/utils';
/** Goal lifecycle state β†’ i18n status key (goal list vocabulary). */
const goalStatusKeyMap = {
@@ -17,13 +18,9 @@ export type GoalStatusKey = (typeof goalStatusKeyMap)[GoalStatus];
export const goalStatusKey = (status: GoalStatus): GoalStatusKey => goalStatusKeyMap[status];
-/** `1h 23m` / `4m` β€” locale-neutral compact span for header metrics and drill-downs. */
-export const formatSpan = (ms: number): string => {
- const minutes = Math.max(1, Math.round(ms / 60_000));
- const h = Math.floor(minutes / 60);
- const m = minutes % 60;
- return h > 0 ? `${h}h ${m}m` : `${m}m`;
-};
+/** `4m` / `1h 23m` / `1d 2h 5m` β€” locale-neutral compact span for header metrics and drill-downs. */
+export const formatSpan = (ms: number): string =>
+ formatDuration(Math.max(1, Math.round(ms / 60_000)) * 60_000, { minUnit: 'm' });
/** Goal lifecycle state β†’ the execution-status vocabulary the shared glyphs use. */
export const goalStatusToTaskStatus = (goalStatus: GoalStatus): TaskStatus => {
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx
index 745e71ea699..1ada30d8ede 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TopicCard.tsx
@@ -1,4 +1,5 @@
import type { TaskDetailActivity } from '@lobechat/types';
+import { formatDuration } from '@lobechat/utils';
import {
Block,
type DropdownItem,
@@ -41,15 +42,6 @@ import RunVerifyTag from './RunVerifyTag';
import { shouldShowRunFollowUp } from './shouldShowRunFollowUp';
import TopicStatusIcon from './TopicStatusIcon';
-const formatDuration = (ms: number): string => {
- const seconds = Math.floor(ms / 1000);
- if (seconds < 60) return `${seconds}s`;
- const minutes = Math.floor(seconds / 60);
- if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
- const hours = Math.floor(minutes / 60);
- return `${hours}h ${minutes % 60}m`;
-};
-
// The run's last message (`content`) is the raw assistant output β€” markdown, and
// often long. Render it as rich text, but keep it a bounded preview in the feed:
// the shared collapse clamps it with a fade and offers "show more", while the
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx
index 62a630404aa..88a4d6a127f 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx
@@ -81,7 +81,7 @@ describe('ExecutionTime', () => {
expect(screen.getByText('0ms')).toBeTruthy();
});
- it('formats elapsed times longer than a minute as Xmin Ys', () => {
+ it('formats elapsed times longer than a minute as Xm Ys', () => {
vi.useFakeTimers();
vi.setSystemTime(10_000);
@@ -93,7 +93,7 @@ describe('ExecutionTime', () => {
vi.advanceTimersByTime(83_000);
});
- expect(screen.getByText('1min23s')).toBeTruthy();
+ expect(screen.getByText('1m 23s')).toBeTruthy();
rerender(<ExecutionTime isExecuting startTime={10_000} timerKey="tool-minutes" />);
@@ -101,7 +101,7 @@ describe('ExecutionTime', () => {
vi.advanceTimersByTime(60_000);
});
- expect(screen.getByText('2min23s')).toBeTruthy();
+ expect(screen.getByText('2m 23s')).toBeTruthy();
});
it('clears the cached start time when execution stops', () => {
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx
index a2d494cc273..c03115d6ed8 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx
@@ -1,3 +1,4 @@
+import { formatDuration } from '@lobechat/utils';
import { Text } from '@lobehub/ui/base-ui';
import { memo, useEffect, useState } from 'react';
@@ -37,10 +38,7 @@ const formatElapsedTime = (ms: number): string => {
const seconds = ms / 1000;
if (seconds < 60) return `${seconds.toFixed(1)}s`;
- const totalSeconds = Math.floor(seconds);
- const minutes = Math.floor(totalSeconds / 60);
- const remainingSeconds = totalSeconds % 60;
- return `${minutes}min${remainingSeconds}s`;
+ return formatDuration(ms);
};
const ExecutionTime = memo<ExecutionTimeProps>(({ isExecuting, startTime, timerKey }) => {
diff --git a/src/features/Conversation/Messages/AssistantGroup/constants.ts b/src/features/Conversation/Messages/AssistantGroup/constants.ts
index 6ef2a3daf51..a8d5fb4cf53 100644
--- a/src/features/Conversation/Messages/AssistantGroup/constants.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/constants.ts
@@ -62,15 +62,9 @@ export const TOOL_HEADLINE_TRUNCATION_SUFFIX = '...';
// ─── Time formatting (workflow summary / reasoning suffix) ───────────────
-/** Seconds per minute when formatting durations like "2m 30s". */
-export const DURATION_SECONDS_PER_MINUTE = 60;
-
/** Duration inputs are in milliseconds; convert to whole seconds for display. */
export const TIME_MS_PER_SECOND = 1000;
-/** Minutes per hour; long turns roll up to "4h 11m" instead of "251m 49s". */
-export const DURATION_MINUTES_PER_HOUR = 60;
-
// ─── apiName β†’ i18n key for human-readable label (workflow summary & headlines) ─
/** Translation keys for built-in / known tool api names. Unknown api names use title-cased fallback. */
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
index ca54426893a..4581179da18 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
@@ -3,14 +3,13 @@ import {
formatLinearMcpShortLabel,
} from '@lobechat/builtin-tool-claude-code/client/labels';
import type { ChatToolPayloadWithResult } from '@lobechat/types';
+import { formatDuration } from '@lobechat/utils';
import { t } from 'i18next';
import { LOADING_FLAT } from '@/const/message';
import type { AssistantContentBlock } from '@/types/index';
import {
- DURATION_MINUTES_PER_HOUR,
- DURATION_SECONDS_PER_MINUTE,
TIME_MS_PER_SECOND,
TOOL_API_DISPLAY_NAMES,
TOOL_HEADLINE_DETAIL_MAX_CHARS,
@@ -329,20 +328,8 @@ export const getWorkflowStreamingHeadlineState = (
* Hour-scale turns roll up to "4h 11m": seconds are noise next to hours, and a
* bare "251m 49s" makes the reader do the division themselves.
*/
-export const formatReasoningDuration = (ms: number): string => {
- const totalSeconds = Math.round(ms / TIME_MS_PER_SECOND);
- if (totalSeconds < DURATION_SECONDS_PER_MINUTE) return `${totalSeconds}s`;
-
- const totalMinutes = Math.floor(totalSeconds / DURATION_SECONDS_PER_MINUTE);
- const seconds = totalSeconds % DURATION_SECONDS_PER_MINUTE;
-
- if (totalMinutes < DURATION_MINUTES_PER_HOUR)
- return seconds > 0 ? `${totalMinutes}m ${seconds}s` : `${totalMinutes}m`;
-
- const hours = Math.floor(totalMinutes / DURATION_MINUTES_PER_HOUR);
- const minutes = totalMinutes % DURATION_MINUTES_PER_HOUR;
- return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
-};
+export const formatReasoningDuration = (ms: number): string =>
+ formatDuration(Math.round(ms / TIME_MS_PER_SECOND) * TIME_MS_PER_SECOND, { trimZero: true });
/**
* Collapsed-workflow summary: the total number of tool calls, nothing more.
diff --git a/src/features/Conversation/Messages/Tasks/shared/utils.ts b/src/features/Conversation/Messages/Tasks/shared/utils.ts
index d629fd28f84..0edd2c0e5ea 100644
--- a/src/features/Conversation/Messages/Tasks/shared/utils.ts
+++ b/src/features/Conversation/Messages/Tasks/shared/utils.ts
@@ -4,19 +4,18 @@ import {
type TaskCurrentActivity,
} from '@lobechat/types';
import { ThreadStatus } from '@lobechat/types';
+import { formatDuration as formatDurationMs, formatElapsedClockTime } from '@lobechat/utils';
/**
* Format duration in milliseconds to human-readable string
* @param duration Duration in milliseconds
- * @returns Formatted string like "500ms", "1.5s", "2m 30s"
+ * @returns Formatted string like "500ms", "1.5s", "2m 30s", "1h 5m", "1d 2h 5m"
*/
export const formatDuration = (duration: number | undefined | null): string | null => {
if (!duration) return null;
if (duration < 1000) return `${duration}ms`;
if (duration < 60_000) return `${(duration / 1000).toFixed(1)}s`;
- const minutes = Math.floor(duration / 60_000);
- const seconds = ((duration % 60_000) / 1000).toFixed(0);
- return `${minutes}m ${seconds}s`;
+ return formatDurationMs(Math.round(duration / 1000) * 1000);
};
/**
@@ -31,20 +30,11 @@ export const formatCost = (cost: number | undefined | null): string | null => {
};
/**
- * Format elapsed time in milliseconds to mm:ss or hh:mm:ss format
+ * Format elapsed time in milliseconds as a running clock
* @param ms Milliseconds
- * @returns Formatted string like "2:30" or "1:02:30"
+ * @returns Formatted string like "02:30", "1:02:30" or "1d 01:02:30"
*/
-export const formatElapsedTime = (ms: number): string => {
- const seconds = Math.floor(ms / 1000);
- const minutes = Math.floor(seconds / 60);
- const hours = Math.floor(minutes / 60);
-
- if (hours > 0) {
- return `${hours}:${String(minutes % 60).padStart(2, '0')}:${String(seconds % 60).padStart(2, '0')}`;
- }
- return `${minutes}:${String(seconds % 60).padStart(2, '0')}`;
-};
+export const formatElapsedTime = (ms: number): string => formatElapsedClockTime(ms);
/**
* Format tool name from activity identifier and apiName
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts b/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts
index 9e8f1076e59..0f94d7f8a05 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts
@@ -1,4 +1,5 @@
import type { DeviceGitLinkedPullRequest, DeviceGitPullRequestCheck } from '@lobechat/types';
+import { formatDuration } from '@lobechat/utils';
import { cssVar } from 'antd-style';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
@@ -91,8 +92,7 @@ export const formatCheckDuration = (check: DeviceGitPullRequestCheck) => {
0,
dayjs(check.completedAt ?? undefined).diff(check.startedAt, 'second'),
);
- const minutes = Math.floor(seconds / 60);
- return minutes > 0 ? `${minutes}m ${String(seconds % 60).padStart(2, '0')}s` : `${seconds}s`;
+ return formatDuration(seconds * 1000, { pad: true });
};
export const timeAgo = (iso: string) => dayjs(iso).fromNow(true);
diff --git a/src/features/Portal/VerifyResult/Body.tsx b/src/features/Portal/VerifyResult/Body.tsx
index e32a2032327..fe135257dea 100644
--- a/src/features/Portal/VerifyResult/Body.tsx
+++ b/src/features/Portal/VerifyResult/Body.tsx
@@ -1,4 +1,5 @@
import type { VerifierType } from '@lobechat/types';
+import { formatDuration as formatDurationMs } from '@lobechat/utils';
import { Flexbox, Markdown } from '@lobehub/ui';
import { Button, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar } from 'antd-style';
@@ -87,7 +88,8 @@ const formatDuration = (started?: Date | string | null, completed?: Date | strin
if (!started || !completed) return null;
const ms = +new Date(completed) - +new Date(started);
if (!Number.isFinite(ms) || ms <= 0) return null;
- return ms >= 1000 ? `${(ms / 1000).toFixed(1)}s` : `${ms}ms`;
+ if (ms < 1000) return `${ms}ms`;
+ return ms < 60_000 ? `${(ms / 1000).toFixed(1)}s` : formatDurationMs(ms);
};
const Field = memo<{ children: ReactNode; label: string }>(({ label, children }) => {
diff --git a/src/features/Settings/stats/features/visualization/HeatmapStats.tsx b/src/features/Settings/stats/features/visualization/HeatmapStats.tsx
index 2d4da1c1c23..5fdca867433 100644
--- a/src/features/Settings/stats/features/visualization/HeatmapStats.tsx
+++ b/src/features/Settings/stats/features/visualization/HeatmapStats.tsx
@@ -1,3 +1,4 @@
+import { formatDuration as formatDurationMs } from '@lobechat/utils';
import { Block, Flexbox } from '@lobehub/ui';
import { Skeleton } from '@lobehub/ui/base-ui';
import { Divider } from 'antd';
@@ -19,12 +20,7 @@ import { HeatmapType } from '../../types';
*/
const formatDuration = (seconds?: number) => {
if (!seconds || seconds < 1) return '--';
- const h = Math.floor(seconds / 3600);
- const m = Math.floor((seconds % 3600) / 60);
- const s = Math.floor(seconds % 60);
- if (h > 0) return `${h}h ${m}m`;
- if (m > 0) return `${m}m ${s}s`;
- return `${s}s`;
+ return formatDurationMs(seconds * 1000);
};
/**
diff --git a/src/routes/(main)/eval/utils.ts b/src/routes/(main)/eval/utils.ts
index ead725a4e46..7b21f06e335 100644
--- a/src/routes/(main)/eval/utils.ts
+++ b/src/routes/(main)/eval/utils.ts
@@ -1,13 +1,6 @@
-export const formatDuration = (ms: number): string => {
- const totalSeconds = Math.floor(ms / 1000);
- const hours = Math.floor(totalSeconds / 3600);
- const minutes = Math.floor((totalSeconds % 3600) / 60);
- const seconds = totalSeconds % 60;
+import { formatDuration as formatDurationMs } from '@lobechat/utils';
- if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
- if (minutes > 0) return `${minutes}m ${seconds}s`;
- return `${seconds}s`;
-};
+export const formatDuration = (ms: number): string => formatDurationMs(ms, { minUnit: 's' });
export const formatDurationMinutes = (ms: number): string => {
const minutes = Math.round(ms / 60_000);