util: formatDuration func

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-04-10 22:27:07 +02:00
parent f630d6c05e
commit e12c042e86
2 changed files with 46 additions and 0 deletions

View File

@@ -204,4 +204,20 @@ export class Util {
const rcp = path.resolve(childPath);
return rcp.startsWith(rpp.endsWith(path.sep) ? rpp : `${rpp}${path.sep}`);
}
public static formatDuration(ns: number): string {
if (ns === 0) return '0s';
const totalSeconds = Math.floor(ns / 1e9);
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
const parts: string[] = [];
if (hours) parts.push(`${hours}h`);
if (minutes) parts.push(`${minutes}m`);
if (seconds || parts.length === 0) parts.push(`${seconds}s`);
return parts.join('');
}
}