pixai / src /shared /duration.ts
ghuser1's picture
Upload 69 files
f703ba6 verified
raw
history blame contribute delete
455 Bytes
export function elapsedMs(startedAtMs: number, nowMs: number = Date.now()): number {
return Math.max(0, nowMs - startedAtMs)
}
export function formatDuration(ms: number): string {
const safe = Math.max(0, ms)
const totalSeconds = Math.floor(safe / 1000)
if (totalSeconds < 60) {
return `${totalSeconds}s`
}
const minutes = Math.floor(totalSeconds / 60)
const seconds = totalSeconds - minutes * 60
return `${minutes}m ${seconds}s`
}