export function formatDuration(ms: number): string { if (isNaN(ms) || ms < 0) return '0:00' // Convert milliseconds to seconds const totalSeconds = Math.floor(ms / 1000) // Calculate hours, minutes, and remaining seconds const hours = Math.floor(totalSeconds / 3600) const minutes = Math.floor((totalSeconds % 3600) / 60) const seconds = totalSeconds % 60 // Format based on duration if (hours > 0) { return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}` } else { return `${minutes}:${seconds.toString().padStart(2, '0')}` } }