All files / shared / components DurationDisplay.tsx

75% Statements 30/40
62.5% Branches 20/32
75% Functions 6/8
82.14% Lines 23/28

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 1937x     200x 200x 196x 196x 196x 3x 3x 2x 2x 2x 608x     6x    
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>
}