fix: 🐛 Fix how utils.humanTime() works

This commit is contained in:
Kenny 2022-05-05 08:18:38 -04:00
parent c6c471b1a2
commit 9acc1ceef4
1 changed files with 17 additions and 11 deletions

View File

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