Fix uptime negative time error by saving it as UTC from the start.

This commit is contained in:
luukas 2021-04-18 00:20:23 +03:00
parent 9049e44803
commit 736924c839
4 changed files with 15 additions and 25 deletions

View File

@ -130,8 +130,8 @@ class Server:
self.process = pexpect.spawn(self.server_command, cwd=self.server_path, timeout=None, encoding=None)
self.is_crashed = False
ts = time.time()
self.start_time = str(datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
# see https://docs.python.org/3/library/datetime.html#datetime.datetime.now
self.start_time = str(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
if psutil.pid_exists(self.process.pid):
self.PID = self.process.pid

View File

@ -86,11 +86,8 @@
let startedLocal;
if (started != null) {
console.log('88', '{{ data['server_stats']['started'] }}');
{% if data['server_stats']['started'] != 'False' %}
startedUTC = '{{ (datetime.datetime.strptime(data['server_stats']['started'], '%Y-%m-%d %H:%M:%S') - datetime.timedelta(seconds=-time.timezone)).strftime('%Y-%m-%d %H:%M:%S') }}';
{% end %}
console.log('utc', startedUTC);
startedUTC = '{{ data['server_stats']['started'] }}';
console.log('started utc:', startedUTC);
startedUTC = moment.utc(startedUTC, 'YYYY-MM-DD HH:mm:ss');
let browserUTCOffset = moment().utcOffset(); // This is in minutes
@ -98,32 +95,25 @@
startedLocal = startedUTC.utcOffset(browserUTCOffset);
startedLocalFormatted = startedLocal.format('YYYY-MM-DD HH:mm:ss');
console.log('startedLocal', startedLocal);
console.log('startedLocalFormatted', startedLocalFormatted);
console.log('started local time:', startedLocalFormatted);
started.textContent = startedLocalFormatted
}
let nowServerTime = '{{ data['time'] }}';
let startedServerTime = '{{ data['server_stats']['started'] }}';
if (uptime != null && started != null) {
var msdiff = moment(nowServerTime,"YYYY-MM-DD hh:mm:ss")
.diff(moment(startedServerTime,"YYYY-MM-DD hh:mm:ss"));
var diff = moment.duration(msdiff);
uptime.textContent = durationToHumanizedString(diff);
console.log('startedLocal', startedLocal)
if (startedLocal) {
var uptimeLoop = setInterval(() => {
var calculateUptime = () => {
var msdiff = moment()
.diff(startedLocal);
var diff = moment.duration(msdiff);
uptime.textContent = durationToHumanizedString(diff);
}, 1000)
}
if (uptime != null && started != null) {
console.log('startedLocal', startedLocal)
if (startedLocal) {
calculateUptime()
var uptimeLoop = setInterval(calculateUptime, 1000)
}
}

View File

@ -106,7 +106,7 @@
"version": "Version",
"description": "Description",
"errorCalculatingUptime": "Error Calculating Uptime",
"serverTime": "Server Time",
"serverTime": "UTC Time",
"unableToConnect": "Unable To Connect"
},
"serverDetails": {

View File

@ -106,7 +106,7 @@
"version": "Versio",
"description": "Kuvaus",
"errorCalculatingUptime": "Virhe laskettaessa käyttöaikaa",
"serverTime": "Palvelimen aikaa",
"serverTime": "UTC aikaa",
"unableToConnect": "Yhteyden muodostaminen epäonnistui"
},
"serverDetails": {