From dc0157cf1f392c8a8424e164b20ca6783f34d118 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Sat, 28 May 2022 21:30:30 +0200 Subject: [PATCH 1/2] [time_utils] Fix typo --- modules/time_utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/time_utils.js b/modules/time_utils.js index 5ca153710..0fdc788ba 100644 --- a/modules/time_utils.js +++ b/modules/time_utils.js @@ -55,7 +55,7 @@ exports.decodeTime = (millis) => { */ exports.formatTime = (value) => { var time = safeTime(typeof value === "object" ? value : exports.decodeTime(value)); - if (time.d != 0) throw "(d)ays not supported here"; + if (time.d != 0) throw "days not supported here"; if (time.h < 0 || time.h > 23) throw "Invalid value: must be 0 <= h <= 23"; if (time.m < 0 || time.m > 59) throw "Invalid value: must be 0 <= m <= 59"; return time.h + ":" + ("0" + time.m).substr(-2); From 889de43d263d5dbd6f971370b722059d4aa6d481 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Sat, 28 May 2022 21:30:50 +0200 Subject: [PATCH 2/2] [time_utils] Add compact mode to formatDuration --- modules/time_utils.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/time_utils.js b/modules/time_utils.js index 0fdc788ba..6a3ed6faf 100644 --- a/modules/time_utils.js +++ b/modules/time_utils.js @@ -63,16 +63,19 @@ exports.formatTime = (value) => { /** * @param {object|int} value {d, h, m, s} object or milliseconds - * @returns an human-readable duration string like "3d 1h 10m 45s" + * @param {boolean} compact `true` to remove all whitespaces between the values + * @returns an human-readable duration string like "3d 1h 10m 45s" (or "3d1h10m45s" if `compact` is `true`) */ -exports.formatDuration = (value) => { +exports.formatDuration = (value, compact) => { + compact = compact || false; var duration = ""; var time = safeTime(typeof value === "object" ? value : exports.decodeTime(value)); if (time.d > 0) duration += time.d + "d "; if (time.h > 0) duration += time.h + "h "; if (time.m > 0) duration += time.m + "m "; if (time.s > 0) duration += time.s + "s" - return duration.trim(); + duration = duration.trim() + return compact ? duration.replace(" ", "") : duration; } exports.getCurrentTimeMillis = () => {