Teach format_duration to handle negative durations

This commit is contained in:
Eevee (Evelyn Woods) 2021-01-03 13:48:23 -07:00
parent 9cf2b82c8e
commit 0f1afbb877

View File

@ -189,11 +189,16 @@ export function b64decode(data) {
} }
export function format_duration(seconds, places = 0) { export function format_duration(seconds, places = 0) {
let sign = '';
if (seconds < 0) {
seconds = -seconds;
sign = '-';
}
let mins = Math.floor(seconds / 60); let mins = Math.floor(seconds / 60);
let secs = seconds % 60; let secs = seconds % 60;
let rounded_secs = secs.toFixed(places); let rounded_secs = secs.toFixed(places);
// TODO hours? // TODO hours?
return `${mins}:${parseFloat(rounded_secs) < 10 ? '0' : ''}${rounded_secs}`; return `${sign}${mins}:${parseFloat(rounded_secs) < 10 ? '0' : ''}${rounded_secs}`;
} }
export class DelayTimer { export class DelayTimer {