util: formatDuration func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
16
src/util.ts
16
src/util.ts
@@ -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('');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user