parse-ms-2
Version:
This is an improved version of parse-ms
17 lines (15 loc) • 523 B
JavaScript
function run(milliseconds) {
if (typeof milliseconds !== 'number') {
throw new TypeError('Expected a number');
}
return {
days: Math.trunc(milliseconds / 86400000),
hours: Math.trunc(milliseconds / 3600000) % 24,
minutes: Math.trunc(milliseconds / 60000) % 60,
seconds: Math.trunc(milliseconds / 1000) % 60,
milliseconds: Math.trunc(milliseconds) % 1000,
microseconds: Math.trunc(milliseconds * 1000) % 1000,
nanoseconds: Math.trunc(milliseconds * 1e6) % 1000
};
}
module.exports = run