-
Notifications
You must be signed in to change notification settings - Fork 62
/
slots.js
59 lines (46 loc) · 1.09 KB
/
slots.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
58
59
function beginEpochTime() {
var d = new Date(1462953000000);
return d;
}
function getEpochTime(time) {
if (time === undefined) {
time = (new Date()).getTime();
}
var d = beginEpochTime();
var t = d.getTime();
return Math.floor((time - t) / 1000);
}
module.exports = {
interval: 10,
delegates: 20,
getTime: function(time) {
return getEpochTime(time);
},
getRealTime: function(epochTime) {
if (epochTime === undefined) {
epochTime = this.getTime()
}
var d = beginEpochTime();
var t = Math.floor(d.getTime() / 1000) * 1000;
return t + epochTime * 1000;
},
getSlotNumber: function(epochTime) {
if (epochTime === undefined) {
epochTime = this.getTime()
}
return Math.floor(epochTime / this.interval);
},
getSlotTime: function(slot) {
return slot * this.interval;
},
getNextSlot: function() {
var slot = this.getSlotNumber();
return slot + 1;
},
getLastSlot: function(nextSlot) {
return nextSlot + this.delegates;
},
roundTime: function(date) {
Math.floor(date.getTime() / 1000) * 1000
}
}