Skip to content

Commit eca712e

Browse files
refactor: natural time display
1 parent 72fdb68 commit eca712e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/commands/stats.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,20 @@ function formatStatsMessage(
5050
}
5151

5252
function formatCompressionTime(ms: number): string {
53-
if (ms < 1000) {
54-
return `${ms} ms`
53+
const totalSeconds = Math.max(0, Math.round(ms / 1000))
54+
if (totalSeconds < 60) {
55+
return `${totalSeconds} s`
5556
}
5657

57-
const seconds = ms / 1000
58-
return `${seconds.toFixed(seconds < 10 ? 2 : 1)} s`
58+
const hours = Math.floor(totalSeconds / 3600)
59+
const minutes = Math.floor((totalSeconds % 3600) / 60)
60+
const seconds = totalSeconds % 60
61+
62+
if (hours > 0) {
63+
return `${hours}h ${minutes}m ${seconds}s`
64+
}
65+
66+
return `${minutes}m ${seconds}s`
5967
}
6068

6169
export async function handleStatsCommand(ctx: StatsCommandContext): Promise<void> {

0 commit comments

Comments
 (0)