forked from HSLdevcom/digitransit-ui
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTimeStore.js
37 lines (29 loc) · 851 Bytes
/
TimeStore.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
import Store from 'fluxible/addons/BaseStore';
import moment from 'moment-timezone';
class TimeStore extends Store {
static storeName = 'TimeStore';
static TWICE_PER_MINUTE = 30 * 1000;
config = {};
constructor(dispatcher) {
super(dispatcher);
this.config = dispatcher.getContext().config;
this.updateCurrentTime();
setInterval(this.updateCurrentTime, TimeStore.TWICE_PER_MINUTE);
}
updateCurrentTime = () => {
if (this.config.NODE_ENV === 'test') {
// Set current time to Tue Dec 28 2021 for E2E-tests
this.currentTime = moment('2021-12-28T12:57:00+00:00');
} else {
this.currentTime = moment();
}
this.emitChange({
currentTime: this.currentTime,
});
};
getCurrentTime() {
return this.currentTime.clone();
}
static handlers = {};
}
export default TimeStore;