Skip to content
Source
Sign inSign up
Open History to see the last commit

TimelineWorkGroupRows.logic.ts

20 lines670 Bytes

1import { formatDuration } from "@t3tools/shared/orchestrationTiming";
2​
3function formatWorkingTimer(startIso: string, endIso: string): string | null {
4 const startedAtMs = Date.parse(startIso);
5 const endedAtMs = Date.parse(endIso);
6 if (!Number.isFinite(startedAtMs) || !Number.isFinite(endedAtMs)) {
7 return null;
8 }
9​
10 const elapsedSeconds = Math.max(0, Math.floor((endedAtMs - startedAtMs) / 1000));
11 if (elapsedSeconds < 60) {
12 return `${elapsedSeconds}s`;
13 }
14​
15 return formatDuration(elapsedSeconds * 1_000);
17​
18export function formatWorkingTimerNow(startIso: string): string {
19 return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";