From f284315e44d29fa439b1707617fb850951597aee Mon Sep 17 00:00:00 2001 From: Rapture <166316975+ftrapture@users.noreply.github.com> Date: Sun, 20 Oct 2024 22:53:49 +0530 Subject: [PATCH] Update Util.js Updated the handling of small time values and rounding up fractional seconds. --- plugins/Util.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/Util.js b/plugins/Util.js index 25976e6..c9a503a 100644 --- a/plugins/Util.js +++ b/plugins/Util.js @@ -13,8 +13,22 @@ module.exports = class Util { * @returns {string} */ static format_time(time) { - if (!time) return "00:00"; - const format = dayjs.duration(time).format("DD:HH:mm:ss"); + if (!time || time < 1) return "00:00"; + + const duration = dayjs.duration(time); + let seconds = duration.seconds(); + + if (seconds < 1 && time > 0) { + seconds = 1; + } + + const format = dayjs.duration({ + days: duration.days(), + hours: duration.hours(), + minutes: duration.minutes(), + seconds: seconds, + }).format("HH:mm:ss"); + const chunks = format.split(":").filter(c => c !== "00"); if (chunks.length < 2) chunks.unshift("00"); @@ -51,4 +65,4 @@ module.exports = class Util { function componentToHex(c){ const hex = c.toString(16); return hex.length == 1 ? "0" + hex : hex; -} \ No newline at end of file +}