-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeydispatcher.js
40 lines (27 loc) · 943 Bytes
/
keydispatcher.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
var custom_date = require("date-format-lite");
var EventEmitter = require('events');
util = require('util');
function KeyDispatcher(options){
EventEmitter.call(this);
var options = options || {
timeInterval : 3000
}
var now = new Date()
this.last = now
this.lastMillisecs = now.getTime()
this.date = now.format('YYYY-MM-DD/hh:00')
this.interval = setInterval(() => {
var now = new Date()
var oldDate = this.date
var currentDateMillisecs = now.getTime()
this.last = now;
this.date = now.format('YYYY-MM-DD/hh:00')
this.emit('changed', {oldDate: oldDate, currentDate: this.date, currentDateMillisecs: currentDateMillisecs, lastMillisecs: this.lastMillisecs});
this.lastMillisecs = now.getTime();
}, options.timeInterval);
this.DateFormat = (date) => (new Date(date).format('YYYY-MM-DD/hh:00'))
}
util.inherits(KeyDispatcher, EventEmitter);
module.exports = options => (
new KeyDispatcher(options)
)