All files / src/lib format.ts

100% Statements 9/9
100% Branches 3/3
100% Functions 1/1
100% Lines 9/9

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          1x 13x 13x 13x 13x 6x 6x 7x 7x  
/**
 * Format seconds into a human-readable time string.
 * - Under 1 hour: "M:SS" (e.g. "3:07")
 * - 1 hour or more: "H:MM:SS" (e.g. "1:03:07")
 */
export const formatTime = (seconds: number): string => {
	const h = Math.floor(seconds / 3600);
	const m = Math.floor((seconds % 3600) / 60);
	const s = Math.floor(seconds % 60);
	if (h > 0) {
		return `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
	}
	return `${m}:${String(s).padStart(2, "0")}`;
};