From 9acc1ceef4f9d340f7e559a1c4fb8cc91f7b23df Mon Sep 17 00:00:00 2001 From: Kenny <27463495+Frontesque@users.noreply.github.com> Date: Thu, 5 May 2022 08:18:38 -0400 Subject: [PATCH] fix: :bug: Fix how utils.humanTime() works --- NUXT/plugins/utils.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/NUXT/plugins/utils.js b/NUXT/plugins/utils.js index b883f12..b40b13d 100644 --- a/NUXT/plugins/utils.js +++ b/NUXT/plugins/utils.js @@ -78,18 +78,24 @@ function linkParser(url) { const delay = (ms) => new Promise((res) => setTimeout(res, ms)); //--- Convert Time To Human Readable String ---// -function humanTime(givenTime) { - const minutes = Math.floor(givenTime / 60); - const seconds = givenTime - minutes * 60; - const hours = Math.floor(givenTime / 3600); - return { - formatted: (hours ? hours+":" : "") + `${minutes}:${seconds}`, - raw: { - hours: hours, - minutes: minutes, - seconds: seconds - } +function humanTime(seconds) { + let levels = [ + Math.floor(seconds / 31536000), //Years + Math.floor((seconds % 31536000) / 86400), //Days + Math.floor(((seconds % 31536000) % 86400) / 3600), //Hours + Math.floor((((seconds % 31536000) % 86400) % 3600) / 60), //Minutes + (((seconds % 31536000) % 86400) % 3600) % 60, //Seconds + ]; + + let returntext = new String(); + for (const i in levels) { + const num = levels[i].toString().length == 1 ? "0"+levels[i] : levels[i]; // If Number Is Single Digit, Add 0 In Front + + returntext += ":"+num; } + while (returntext.startsWith(":00")) { returntext = returntext.substring(3); } // Remove Prepending 0s (eg. 00:00:00:01:00) + if (returntext.startsWith(":0")) { returntext = returntext.substring(2); } else { returntext = returntext.substring(1); } // Prevent Time Starting With 0 (eg. 01:00) + return returntext } //--- End Convert Time To Human Readable String ---//