From f7933ce92cb7b657b44127d28f33ef59499cf99c Mon Sep 17 00:00:00 2001 From: razonyang Date: Sat, 15 Jun 2024 13:44:48 +0800 Subject: [PATCH] feat: display more detailed total time to include hours, mins and seconds --- src/metrics.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/metrics.ts b/src/metrics.ts index bce0882..3f74e15 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -55,13 +55,19 @@ class Metrics { } duration (): string { - if (this.time > 3600 * 10e2) { - return `${blue(this.time / 3600 / 10e2)} h` - } else if (this.time > 60 * 10e2) { - return `${blue(this.time / 60 / 10e2)} min` + const h = Math.floor(this.time / (10e2 * 3600)) + const m = Math.floor(this.time / (10e2 * 60) % 60) + const s = (this.time / 10e2 % 60) + let v = `${green(s)}s` + + if (m > 0) { + v = `${blue(m)}m` + v + } + if (h > 0) { + v = `${yellow(h)}h` + v } - return `${blue(this.time / 10e2)} s` + return v } speed (): string {