-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (40 loc) · 927 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = function (ms, monthDay) {
let mscast = null;
if(typeof ms == 'string')
{
mscast = Number(new Date(ms)) || 0;
}
else{
mscast = Number(ms) || 0;
}
var neg = mscast < 0;
mscast = Math.abs(mscast);
monthDay = monthDay || 31;
var d, h, m, s, mt, yr,$ms;
s = Math.floor(mscast / 1000);
$ms = mscast % 1000;
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
mt = Math.floor(d / monthDay);
d = d % monthDay;
yr = Math.floor(mt / 12);
mt = mt % 12;
var out = {
microSeconds:$ms,
seconds:s,
minutes:m,
hours:h,
days:d,
months:mt,
years:yr
};
if(neg)
Object.keys(out).map(function(key) {
out[key] = out[key] > 0 ? - out[key] : out[key];
});
return out;
};