-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeUnit.js
45 lines (45 loc) · 912 Bytes
/
TimeUnit.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
/**
* @class TimeUnit
*/
export class TimeUnit {
/**
* @type {Number}
*/
static SECOND = 1000;
/**
* @type {Number}
*/
static MINUTE = 60 * this.SECOND;
/**
* @type {Number}
*/
static HOUR = 60 * this.MINUTE;
/**
* @type {Number}
*/
static DAY = 24 * this.HOUR;
/**
* @type {Number}
*/
static WEEK = 7 * this.DAY;
/**
* @type {Number}
*/
static MONTH = 30 * this.DAY;
/**
* @type {Number}
*/
static YEAR = 365 * this.DAY;
/**
* @param {Number} value
* @returns {String}
*/
static measure(value) {
let absoluteValue = Math.abs(value);
return Object.keys(this).find((key, index, list) => {
let nextKey = list[index + 1];
return nextKey == null || this[nextKey] > absoluteValue;
});
}
}
export default TimeUnit;