Work with Unix timestamps rather than strings for time calculations
This commit is contained in:
parent
5c6121e630
commit
3b623f2693
2 changed files with 5 additions and 4 deletions
|
@ -21,6 +21,7 @@ import tempfile
|
||||||
import crypt
|
import crypt
|
||||||
import tarfile
|
import tarfile
|
||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
|
@ -232,8 +233,8 @@ def ping(request, device_id):
|
||||||
ajax += ',\n "serial": "%s"' % device[0].serial
|
ajax += ',\n "serial": "%s"' % device[0].serial
|
||||||
ajax += ',\n "name": "%s"' % device[0].name if device[0].name else ""
|
ajax += ',\n "name": "%s"' % device[0].name if device[0].name else ""
|
||||||
ajax += ',\n "ip": "%s"' % device[0].curip
|
ajax += ',\n "ip": "%s"' % device[0].curip
|
||||||
ajax += ',\n "time": "%s"' % device[0].lasttime
|
ajax += ',\n "time": "%i"' % (int(time.mktime(timezone.make_naive(device[0].lasttime, timezone.get_current_timezone()).timetuple())) * 1000)
|
||||||
ajax += ',\n "lastbeat": "%s"' % device[0].lastbeat
|
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 "reboot": %i' % (1 if device[0].reboot else 0)
|
||||||
ajax += ',\n "update": %i' % (1 if device[0].update else 0)
|
ajax += ',\n "update": %i' % (1 if device[0].update else 0)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function timeSince(obj) {
|
function timeSince(obj) {
|
||||||
last = new Date(obj)
|
last = new Date(Number(obj));
|
||||||
var seconds = Math.floor((new Date() - last) / 1000);
|
var seconds = Math.floor((new Date() - last) / 1000);
|
||||||
interval = Math.floor(seconds / 3600);
|
interval = Math.floor(seconds / 3600);
|
||||||
out = "";
|
out = "";
|
||||||
|
@ -12,7 +12,7 @@ function timeSince(obj) {
|
||||||
if (seconds < 120) out = seconds + " seconds "
|
if (seconds < 120) out = seconds + " seconds "
|
||||||
else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
|
else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
|
||||||
|
|
||||||
return out + "ago"
|
return out + "ago";
|
||||||
}
|
}
|
||||||
|
|
||||||
function styleStatus(msg, device) {
|
function styleStatus(msg, device) {
|
||||||
|
|
Loading…
Reference in a new issue