Trying to convert minutes per total number of episodes into days, hours, and minutes but I can't figure out the proper formula for hours.
function minToDays(min, ep) {
let days = parseInt((min * ep) / 1440);
let hours = parseInt(((min * ep) % 60));
let remainingMin = hours % 60;
return `${days} day(s) and ${hours} hour(s) and ${remainingMin} minutes(s).`;
}
console.log(minToDays(20, 800)); //11 days, 2 hours, 40 minutes
A bit clunky, but here's a quick way to see the logic - each time you need to see what minutes remain. I'm sure someone with more time will give you a more elegnat answer:
function minToDays(min, ep) {
let days = Math.floor((min * ep) / 1440);
let remainingTime = parseInt((min*ep) - Math.floor((days *1440)));
let hours = Math.floor((remainingTime / 60));
let remainingMin = Math.floor(remainingTime - (hours*60));
return `${days} day(s) and ${hours} hour(s) and ${remainingMin} minutes(s).`;
}
console.log(minToDays(20, 800)); //11 days, 2 hours, 40 minutes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With