feat: implement ThemeProvider and SoundCard components; add utility functions for formatting duration and size
This commit is contained in:
18
src/utils/format-duration.ts
Normal file
18
src/utils/format-duration.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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')}`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user