Fixes a timer bug, improves function naming

Fixes a bug in the timer visual that made it go from 0:59 to 0:00 to 1:00, which is extremely confusing, especially for the total time and the pace.
Fixes the name, as it used to be secondsToPace, and was used for totalTime as well.
This commit is contained in:
Jaap van Ekris 2023-04-27 17:49:52 +02:00 committed by GitHub
parent c4aeb50891
commit f896a91af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -17,21 +17,21 @@ export function filterObjectByKeys (object, keys) {
}
/**
* Pipe for converting seconds to pace format 00:00
* Pipe for converting seconds to a human readable time format 00:00
*
* @param {number} seconds The actual time in seconds.
*/
export function secondsToPace (seconds) {
const hours = Math.floor((seconds % 86400) / 3600)
const mins = Math.floor(((seconds % 86400) % 3600) / 60)
if (seconds === undefined || seconds === null || seconds === Infinity || isNaN(seconds)) return '--'
export function secondsToTimeString (timeInSeconds) {
if (timeInSeconds === undefined || timeInSeconds === null || isNaN(timeInSeconds)) return '--'
if (timeInSeconds === Infinity) return '∞'
const timeInRoundedSeconds = Math.round(timeInSeconds)
const hours = Math.floor(timeInRoundedSeconds / 3600)
const minutes = Math.floor(timeInRoundedSeconds / 60) - (hours * 60)
const seconds = Math.floor(timeInRoundedSeconds % 60)
if (hours > 0) {
return `${hours}:${mins.toString().padStart(2, '0')}:${(Math.round(seconds) % 60)
.toString()
.padStart(2, '0')}`
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
} else {
return `${mins}:${(Math.round(seconds) % 60).toString().padStart(2, '0')}`
return `${minutes}:${seconds.toString().padStart(2, '0')}`
}
}