-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to try to fix track progress going over duration
- Loading branch information
Showing
6 changed files
with
54 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useMemo } from 'react'; | ||
|
||
/** | ||
* Parse an int to a more readable string | ||
*/ | ||
export function parseDuration(maybe_duration: number | null): string { | ||
if (maybe_duration !== null && !Number.isNaN(maybe_duration)) { | ||
const duration = Math.trunc(maybe_duration); | ||
const hours = Math.trunc(duration / 3600); | ||
const minutes = Math.trunc(duration / 60) % 60; | ||
const seconds = Math.trunc(duration) % 60; | ||
|
||
const hoursStringified = hours < 10 ? `0${hours}` : hours; | ||
const minutesStringified = minutes < 10 ? `0${minutes}` : minutes; | ||
const secondsStringified = seconds < 10 ? `0${seconds}` : seconds; | ||
|
||
let result = hours > 0 ? `${hoursStringified}:` : ''; | ||
result += `${minutesStringified}:${secondsStringified}`; | ||
|
||
return result; | ||
} | ||
|
||
return '00:00'; | ||
} | ||
|
||
/** | ||
* Memoize a formatted duration for a given number | ||
*/ | ||
export default function useFormattedDuration(duration: number | null): string { | ||
const durationAsSeconds = duration !== null ? Math.trunc(duration) : null; | ||
|
||
const display = useMemo(() => { | ||
return parseDuration(durationAsSeconds); | ||
}, [durationAsSeconds]); | ||
|
||
return display; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters