forked from magtimmermans/com.cyclone-software.sunevents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
triggerEvent.js
50 lines (36 loc) · 1.07 KB
/
triggerEvent.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
const moment = require("moment");
const TriggerEvent = function(id, when, offset) {
const self = this;
//console.log(when);
// if no date give get todays date
var dt_now = new Date();
var dt_when = when;
if (when === undefined) {
dt_when = dt_now;
}
if (offset === undefined) {
offset = 0;
}
if (offset) {
dt_when = moment(dt_when).add(offset, 'minutes').toDate();
}
console.log('TriggerEvent: ' + id + ' when:' + dt_when);
self.id = id;
self.theTime = {};
self.theTime.when = dt_when;
self.theTime.offset = offset;
self.theTime.epoch = dt_when.getTime() / 1000.0;
}
TriggerEvent.prototype.compare = function(event) {
const self = this;
var ms_compare;
if (event === undefined) {
ms_compare = (new Date).getTime() / 1000;
} else if (typeof event === "object") {
ms_compare = event.theTime.epoch;
} else {
throw new Error("unrecognized argument", paramd);
}
return self.theTime.epoch - ms_compare;
};
exports.TriggerEvent = TriggerEvent;