From 0f1afbb877162832faaf542beb6ca832515f675c Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Sun, 3 Jan 2021 13:48:23 -0700 Subject: [PATCH] Teach format_duration to handle negative durations --- js/util.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 1647ee0..68bfeb9 100644 --- a/js/util.js +++ b/js/util.js @@ -189,11 +189,16 @@ export function b64decode(data) { } export function format_duration(seconds, places = 0) { + let sign = ''; + if (seconds < 0) { + seconds = -seconds; + sign = '-'; + } let mins = Math.floor(seconds / 60); let secs = seconds % 60; let rounded_secs = secs.toFixed(places); // TODO hours? - return `${mins}:${parseFloat(rounded_secs) < 10 ? '0' : ''}${rounded_secs}`; + return `${sign}${mins}:${parseFloat(rounded_secs) < 10 ? '0' : ''}${rounded_secs}`; } export class DelayTimer {