From 54c825827f304f2932870900041d06eef6708a26 Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Thu, 22 Aug 2024 12:22:48 +0200 Subject: [PATCH] fixing formatSeconds for negative values --- src/libs/time.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/time.js b/src/libs/time.js index 1261621..eb7843c 100644 --- a/src/libs/time.js +++ b/src/libs/time.js @@ -19,12 +19,15 @@ const getAccumulatedSeconds = (newerTime, olderTime) => { } const formatSeconds = (total, includeHours = false) => { - const timeObj = createTimeObj(total) + const timeObj = createTimeObj(Math.abs(total)) + let result = (total < 0) ? '-' : '' if(includeHours) { - return `${timeObj.hours}:${timeObj.minutes.toString().padStart(2,'0')}:${timeObj.seconds.toString().padStart(2,'0')}`; + result += `${timeObj.hours}:${timeObj.minutes.toString().padStart(2,'0')}` } else { - return `${timeObj.hours*60 + timeObj.minutes}:${timeObj.seconds.toString().padStart(2,'0')}`; + result += `${timeObj.hours*60 + timeObj.minutes}` } + result += `:${timeObj.seconds.toString().padStart(2,'0')}` + return result } export { getHours, getMinutes, createTimeObj, getAccumulatedSeconds, formatSeconds }