mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-30 10:56:55 -05:00
17 lines
554 B
JavaScript
17 lines
554 B
JavaScript
/**
|
|
* from codegrepper
|
|
* @param {Number} d seconds
|
|
* @return {String} X hour, X minute, X second
|
|
*/
|
|
function secondsToHms(d) {
|
|
d = Number(d);
|
|
const h = Math.floor(d / 3600);
|
|
const m = Math.floor(d % 3600 / 60);
|
|
const s = Math.floor(d % 3600 % 60);
|
|
const hDisplay = h > 0 ? h + (h == 1 ? ' hour, ' : ' hours, ') : '';
|
|
const mDisplay = m > 0 ? m + (m == 1 ? ' minute, ' : ' minutes, ') : '';
|
|
const sDisplay = s > 0 ? s + (s == 1 ? ' second' : ' seconds') : '';
|
|
return hDisplay + mDisplay + sDisplay;
|
|
}
|
|
|
|
module.exports = {secondsToHms};
|