All files / shared / components DurationDisplay.tsx

65.51% Statements 19/29
54.54% Branches 12/22
66.66% Functions 4/6
68% Lines 17/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1948x     588x 588x 578x 578x 578x           1068x          
interface DurationDisplayProps {
  ms: number | null
}
 
function formatDuration(ms: number): string {
  const totalSec = Math.floor(ms / 1000)
  if (totalSec < 60) return `${totalSec}s`
 E const min = Math.floor(totalSec / 60)
  const sec = totalSec % 60
  if (min < 60) return sec > 0 ? `${min}m ${sec}s` : `${min}m`
  const hours = Math.floor(min / 60)
  const remMin = min % 60
  return remMin > 0 ? `${hours}h ${remMin}m` : `${hours}h`
}
 
export function DurationDisplay({ ms }: DurationDisplayProps) {
  return <span>{ms === null ? '\u2014' : formatDuration(ms)}</span>
}