extract formatting durations

This commit is contained in:
Alex Holliday committed 2026-07-31 12:58:58 -07:00
1 parent 336dbe4de2
commit 19b5976f85
6 files changed
+29 -26

No files matched your search

+17
View File
@@ -103,3 +103,20 @@ export const formatMs = (ms: number, hasSpace: boolean = true): string => {
}
return formatted;
};
export const formatDuration = (ms: number, verbose: boolean = false, hasSpace = true) => {
if (verbose) {
return prettyMilliseconds(ms, { verbose: true });
}
const formatted = prettyMilliseconds(ms, {
unitCount: 2,
secondsDecimalDigits: 0,
millisecondsDecimalDigits: 0,
});
if (hasSpace) {
return formatted.replace(/^(\d+)(\D+)$/, "$1 $2");
}
return formatted;
};