Open History to see the last commit
1import { toServerClock } from "@t3tools/client-runtime/clock";
2import type { EnvironmentId } from "@t3tools/contracts";
3import { formatDuration } from "@t3tools/shared/orchestrationTiming";
4
5export function formatWorkingTimerNow(startIso: string, environmentId: EnvironmentId): string {
6 const startedAtMs = Date.parse(startIso);
7 if (!Number.isFinite(startedAtMs)) {
8 return "0s";
9 }
10
11 const elapsedSeconds = Math.max(
12 0,
13 Math.floor((toServerClock(environmentId, Date.now()) - startedAtMs) / 1000),
14 );
15 if (elapsedSeconds < 60) {
16 return `${elapsedSeconds}s`;
17 }
18
19 return formatDuration(elapsedSeconds * 1_000);
20}