From f896a91af6a2e59889ce26c78a47b177fb5bcfa2 Mon Sep 17 00:00:00 2001 From: Jaap van Ekris <82339657+JaapvanEkris@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:49:52 +0200 Subject: [PATCH] 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. --- app/client/lib/helper.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/client/lib/helper.js b/app/client/lib/helper.js index dbb0aca..a5f382b 100644 --- a/app/client/lib/helper.js +++ b/app/client/lib/helper.js @@ -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')}` } }