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/orchestrationTimingCopy";
4import { msg } from "gt-react";
5import { m } from "~/i18n/messages";
6
7export function formatWorkingTimerNow(startIso: string, environmentId: EnvironmentId): string {
8 const startedAtMs = Date.parse(startIso);
9 if (!Number.isFinite(startedAtMs)) {
10 return m(msg("{seconds}s", { seconds: 0 }));
11 }
12
13 const elapsedSeconds = Math.max(
14 0,
15 Math.floor((toServerClock(environmentId, Date.now()) - startedAtMs) / 1000),
16 );
17 if (elapsedSeconds < 60) {
18 return m(msg("{seconds}s", { seconds: elapsedSeconds }));
19 }
20
21 return formatDuration(elapsedSeconds * 1_000, m);
22}