Roo-Code/apps/web-roo-code/src/lib/format-duration.ts
roomote[bot] 9378a4e2ad
feat: show dash instead of zero for missing data on evals page (#7748)
Co-authored-by: Roo Code <roomote@roocode.com>
2025-09-06 17:15:10 -04:00

26 lines
565 B
TypeScript

export const formatDuration = (durationMs: number | null | undefined) => {
if (durationMs === null || durationMs === undefined) {
return "-"
}
const seconds = Math.floor(durationMs / 1000)
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const remainingSeconds = seconds % 60
const parts = []
if (hours > 0) {
parts.push(`${hours}h`)
}
if (minutes > 0) {
parts.push(`${minutes}m`)
}
if (remainingSeconds > 0 || parts.length === 0) {
parts.push(`${remainingSeconds}s`)
}
return parts.join(" ")
}