From ca494df4008f3e0fa504b06c10783addc18737bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Wed, 25 Aug 2021 22:39:44 +0300 Subject: [PATCH] Updated msToTime function --- src/client/funcs/msToTime.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/client/funcs/msToTime.js b/src/client/funcs/msToTime.js index 666d545..94009a3 100644 --- a/src/client/funcs/msToTime.js +++ b/src/client/funcs/msToTime.js @@ -1,17 +1,12 @@ -module.exports = function msToTime(duration, format) { +module.exports = function msToTime(duration) { var seconds = Math.floor((duration / 1000) % 60), minutes = Math.floor((duration / (1000 * 60)) % 60), hours = Math.floor((duration / (1000 * 60 * 60)) % 24), days = Math.floor((duration / (1000 * 60 * 60 * 24))); - days = (days < 10) ? "0" + days : days; - hours = (hours < 10) ? "0" + hours : hours; - minutes = (minutes < 10) ? "0" + minutes : minutes; - seconds = (seconds < 10) ? "0" + seconds : seconds; - - if (format === "hh:mm:ss") { - return `${hours}:${minutes}:${seconds}`; - } else if (format === "dd:hh:mm:ss") { - return `${days}:${hours}:${minutes}:${seconds}`; - } + return +days > 0 + ? `${days}:${+hours < 10 ? `0${hours}` : hours}:${+minutes < 10 ? `0${minutes}` : minutes}:${+seconds < 10 ? `0${seconds}` : seconds}` + : +hours > 0 + ? `${+hours < 10 ? `0${hours}` : hours}:${+minutes < 10 ? `0${minutes}` : minutes}:${+seconds < 10 ? `0${seconds}` : seconds}` + : `${+minutes < 10 ? `0${minutes}` : minutes}:${+seconds < 10 ? `0${seconds}` : seconds}`; } \ No newline at end of file