All files / Rindu/utils timeStringToSeconds.ts

61.53% Statements 8/13
20% Branches 1/5
100% Functions 2/2
61.53% Lines 8/13

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 19 206x 4x 8x 8x     8x     4x 4x 4x                
export function timeStringToSeconds(timeString: string): number {
  const parts = timeString.split(":").map((part) => {
    const number = Number(part);
    Iif (isNaN(number)) {
      throw new Error("Invalid time format");
    }
    return number;
  });
 
  if (parts.length === 2) {
    const [minutes, seconds] = parts;
    return minutes * 60 + seconds;
  } else Eif (parts.length === 3) {
    const [hours, minutes, seconds] = parts;
    return hours * 3600 + minutes * 60 + seconds;
  } else {
    throw new Error("Invalid time format");
  }
}