mirror of
https://github.com/HSLdevcom/digitransit-ui
synced 2025-07-27 07:04:44 +02:00

It does not make sense to pass current time as moment object. 99% of users convert it to unix time immediately.
36 lines
822 B
JavaScript
36 lines
822 B
JavaScript
import Store from 'fluxible/addons/BaseStore';
|
|
|
|
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 = Math.floor(
|
|
Date.parse('2021-12-28T12:57:00+00:00') / 1000,
|
|
);
|
|
} else {
|
|
this.currentTime = Math.floor(Date.now() / 1000);
|
|
}
|
|
this.emitChange();
|
|
};
|
|
|
|
getCurrentTime() {
|
|
return this.currentTime;
|
|
}
|
|
|
|
static handlers = {};
|
|
}
|
|
|
|
export default TimeStore;
|