You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { tsNow } from '../../helpers/date';
|
|
|
|
import AppStorage from '../storage';
|
|
|
|
|
|
|
|
export class ServerTimeManager {
|
|
|
|
public timestampNow = tsNow(true);
|
|
|
|
public midnightNoOffset = this.timestampNow - (this.timestampNow % 86400);
|
|
|
|
public midnightOffseted = new Date();
|
|
|
|
|
|
|
|
public midnightOffset = this.midnightNoOffset - (Math.floor(+this.midnightOffseted / 1000));
|
|
|
|
|
|
|
|
public serverTimeOffset = 0; // in seconds
|
|
|
|
public timeParams = {
|
|
|
|
midnightOffset: this.midnightOffset,
|
|
|
|
serverTimeOffset: this.serverTimeOffset
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.midnightOffseted.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
AppStorage.get<number>('server_time_offset').then((to) => {
|
|
|
|
if(to) {
|
|
|
|
this.serverTimeOffset = to;
|
|
|
|
this.timeParams.serverTimeOffset = to;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new ServerTimeManager();
|