numbers-words
Version:
numbers-words is a useful package when you are working with numbers. It can converts numbers to words, format numbers and more in the upcoming versions!
18 lines (15 loc) • 473 B
JavaScript
function toTime(seconds) {
if (isNaN(seconds) || seconds < 0) {
throw new Error("Seconds must be greater than 0");
}
// Comment (yes)
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = seconds % 60;
return [
h ? `${h} hour${h !== 1 ? 's' : ''}` : '',
m ? `${m} minute${m !== 1 ? 's' : ''}` : '',
s ? `${s} second${s !== 1 ? 's' : ''}` : ''
].filter(Boolean).join(', ');
}
module.exports = toTime;