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 ---//