mirror of
https://github.com/VueTubeApp/VueTube
synced 2024-11-30 07:03:05 +00:00
fix: 🐛 Fix how utils.humanTime() works
This commit is contained in:
parent
c6c471b1a2
commit
9acc1ceef4
1 changed files with 17 additions and 11 deletions
|
@ -78,18 +78,24 @@ function linkParser(url) {
|
||||||
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
||||||
|
|
||||||
//--- Convert Time To Human Readable String ---//
|
//--- Convert Time To Human Readable String ---//
|
||||||
function humanTime(givenTime) {
|
function humanTime(seconds) {
|
||||||
const minutes = Math.floor(givenTime / 60);
|
let levels = [
|
||||||
const seconds = givenTime - minutes * 60;
|
Math.floor(seconds / 31536000), //Years
|
||||||
const hours = Math.floor(givenTime / 3600);
|
Math.floor((seconds % 31536000) / 86400), //Days
|
||||||
return {
|
Math.floor(((seconds % 31536000) % 86400) / 3600), //Hours
|
||||||
formatted: (hours ? hours+":" : "") + `${minutes}:${seconds}`,
|
Math.floor((((seconds % 31536000) % 86400) % 3600) / 60), //Minutes
|
||||||
raw: {
|
(((seconds % 31536000) % 86400) % 3600) % 60, //Seconds
|
||||||
hours: hours,
|
];
|
||||||
minutes: minutes,
|
|
||||||
seconds: 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 ---//
|
//--- End Convert Time To Human Readable String ---//
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue