forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimes.js
57 lines (53 loc) · 1.61 KB
/
times.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var factories = {
weeks: function weeks(value) {
return {
mins: value * 7 * 24 * 60, secs: value * 7 * 24 * 60 * 60, msecs: value * 7 * 24 * 60 * 60 * 1000
};
}
, days: function days(value) {
return {
hours: value * 24, mins: value * 24 * 60, secs: value * 24 * 60 * 60, msecs: value * 24 * 60 * 60 * 1000
};
}
, hours: function hours(value) {
return {
mins: value * 60, secs: value * 60 * 60, msecs: value * 60 * 60 * 1000
};
}
, mins: function mins(value) {
return {
secs: value * 60, msecs: value * 60 * 1000
};
}
, secs: function secs(value) {
return {
msecs: value * 1000
};
}
, msecs: function msecs(value) {
return {
mins: value / 1000 / 60, secs: value / 1000, msecs: value
};
}
};
function create (types) {
return function withValue (value) {
return factories[types](value);
};
}
var times = {
week: function ( ) { return create('weeks')(1); }
, weeks: function (value) { return create('weeks')(value); }
, day: function ( ) { return create('days')(1); }
, days: function (value) { return create('days')(value); }
, hour: function ( ) { return create('hours')(1); }
, hours: function (value) { return create('hours')(value); }
, min: function ( ) { return create('mins')(1); }
, mins: function (value) { return create('mins')(value); }
, sec: function ( ) { return create('secs')(1); }
, secs: function (value) { return create('secs')(value); }
, msec: function ( ) { return create('msecs')(1); }
, msecs: function (value) { return create('msecs')(value); }
};
module.exports = times;