mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix uptime negative time error by saving it as UTC from the start.
This commit is contained in:
parent
9049e44803
commit
736924c839
@ -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
|
||||
|
@ -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 calculateUptime = () => {
|
||||
var msdiff = moment()
|
||||
.diff(startedLocal);
|
||||
var diff = moment.duration(msdiff);
|
||||
|
||||
uptime.textContent = durationToHumanizedString(diff);
|
||||
}
|
||||
|
||||
if (uptime != null && started != null) {
|
||||
|
||||
console.log('startedLocal', startedLocal)
|
||||
if (startedLocal) {
|
||||
var uptimeLoop = setInterval(() => {
|
||||
var msdiff = moment()
|
||||
.diff(startedLocal);
|
||||
var diff = moment.duration(msdiff);
|
||||
|
||||
uptime.textContent = durationToHumanizedString(diff);
|
||||
}, 1000)
|
||||
calculateUptime()
|
||||
var uptimeLoop = setInterval(calculateUptime, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@
|
||||
"version": "Version",
|
||||
"description": "Description",
|
||||
"errorCalculatingUptime": "Error Calculating Uptime",
|
||||
"serverTime": "Server Time",
|
||||
"serverTime": "UTC Time",
|
||||
"unableToConnect": "Unable To Connect"
|
||||
},
|
||||
"serverDetails": {
|
||||
|
@ -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": {
|
||||
|
Loading…
Reference in New Issue
Block a user