All files / Rindu/utils formatTime.ts

90% Statements 9/10
90.9% Branches 10/11
100% Functions 1/1
90% Lines 9/10

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 1512x 22x       22x 22x 22x 22x 22x 22x   22x    
export function formatTime(seconds: number): string {
  Iif (typeof seconds !== "number" || isNaN(seconds)) {
    return "0:00";
  }
 
  const h = Math.floor(seconds / 3600);
  const m = Math.floor((seconds % 3600) / 60);
  const s = Math.floor((seconds % 3600) % 60);
  const dh = h > 0 ? `${h}:` : "";
  const dm = h > 0 && m < 10 ? `0${m}:` : `${m}:`;
  const ds = s < 10 ? `0${s}` : s;
 
  return `${dh}${dm}${ds}`;
}