Skip to content

Commit e16d7c3

Browse files
committed
bug: add formatter.duration back
1 parent 0ae0795 commit e16d7c3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/utils/misc/formatter.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ export namespace Formatter {
122122
return number(unix / 86400, 1) + ' days'
123123
}
124124

125+
export function duration(ms: number): string {
126+
if (ms <= 0) return "0s"
127+
const s = Math.floor(ms / 1000)
128+
const d = Math.floor(s / 86400)
129+
const h = Math.floor((s % 86400) / 3600)
130+
const m = Math.floor((s % 3600) / 60)
131+
const sec = s % 60
132+
const parts: string[] = []
133+
if (d) parts.push(`${d}d`)
134+
if (h) parts.push(`${h}h`)
135+
if (m) parts.push(`${m}m`)
136+
if (sec || parts.length === 0) parts.push(`${sec}s`)
137+
return parts.join(" ")
138+
}
139+
125140
export function error(msg: string): string {
126141
const regex = /user rejected action\s*\(action="([^"]+)"/i
127142
const match = msg.match(regex)

0 commit comments

Comments
 (0)