You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
417 B
JavaScript
17 lines
417 B
JavaScript
5 years ago
|
'use strict';
|
||
|
module.exports = function (ms) {
|
||
|
if (typeof ms !== 'number') {
|
||
|
throw new TypeError('Expected a number');
|
||
|
}
|
||
|
|
||
|
var roundTowardZero = ms > 0 ? Math.floor : Math.ceil;
|
||
|
|
||
|
return {
|
||
|
days: roundTowardZero(ms / 86400000),
|
||
|
hours: roundTowardZero(ms / 3600000) % 24,
|
||
|
minutes: roundTowardZero(ms / 60000) % 60,
|
||
|
seconds: roundTowardZero(ms / 1000) % 60,
|
||
|
milliseconds: roundTowardZero(ms) % 1000
|
||
|
};
|
||
|
};
|