Work with Unix timestamps rather than strings for time calculations

This commit is contained in:
Kumi 2019-01-13 17:56:00 +01:00
parent 5c6121e630
commit 3b623f2693
2 changed files with 5 additions and 4 deletions

View file

@ -21,6 +21,7 @@ import tempfile
import crypt
import tarfile
import datetime
import time
def index(request):
if request.user.is_authenticated:
@ -232,8 +233,8 @@ def ping(request, device_id):
ajax += ',\n "serial": "%s"' % device[0].serial
ajax += ',\n "name": "%s"' % device[0].name if device[0].name else ""
ajax += ',\n "ip": "%s"' % device[0].curip
ajax += ',\n "time": "%s"' % device[0].lasttime
ajax += ',\n "lastbeat": "%s"' % device[0].lastbeat
ajax += ',\n "time": "%i"' % (int(time.mktime(timezone.make_naive(device[0].lasttime, timezone.get_current_timezone()).timetuple())) * 1000)
ajax += ',\n "lastbeat": "%s"' % (int(time.mktime(timezone.make_naive(device[0].lastbeat, timezone.get_current_timezone()).timetuple())) * 1000)
ajax += ',\n "reboot": %i' % (1 if device[0].reboot else 0)
ajax += ',\n "update": %i' % (1 if device[0].update else 0)

View file

@ -1,5 +1,5 @@
function timeSince(obj) {
last = new Date(obj)
last = new Date(Number(obj));
var seconds = Math.floor((new Date() - last) / 1000);
interval = Math.floor(seconds / 3600);
out = "";
@ -12,7 +12,7 @@ function timeSince(obj) {
if (seconds < 120) out = seconds + " seconds "
else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
return out + "ago"
return out + "ago";
}
function styleStatus(msg, device) {