1
0
Fork 0

hswaw/checkinator: convert timestamp to browsers timezone

Change-Id: Ib7439269bf13de530a5f170bf231f89d815b0f3e
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1246
Reviewed-by: q3k <q3k@hackerspace.pl>
master
vuko 2021-12-28 21:39:28 +01:00
parent 2afcbddf6a
commit 4306994b4e
3 changed files with 27 additions and 6 deletions

View File

@ -9,7 +9,7 @@ Now at hackerspace
{% for user, timestamp in users %}
<li>
<a href="{{ user | wikiurl }}">
{{ user }} ({{ timestamp|strfts() }})
{{ user }} (<span class="timestamp" data-datetime="{{ timestamp|utcisoformat }}">{{ timestamp|strfts() }} UTC</span>)
</a>
</li>
{% endfor %}
@ -31,4 +31,19 @@ Now at hackerspace
{% endtrans %}
<hr>
<a href="claim">Claim this device!</a>
<script>
function formatDate(d) {
function pad(n) {return n<10 ? '0'+n : n};
return d.getFullYear()+'-'
+ pad(d.getMonth()+1)+'-'
+ pad(d.getDate())+' '
+ pad(d.getHours())+':'
+ pad(d.getMinutes());
}
for (const tstamp of document.getElementsByClassName('timestamp')) {
const dt = new Date(tstamp.getAttribute("data-datetime"));
tstamp.innerHTML = formatDate(dt);
}
</script>
{% endblock %}

View File

@ -7,7 +7,7 @@ import re
import subprocess
import logging
from concurrent import futures
from datetime import datetime
from datetime import datetime, timezone
from .tracker_pb2 import DhcpClient, DhcpClients, HwAddrResponse
from .tracker_pb2_grpc import DhcpTrackerServicer, add_DhcpTrackerServicer_to_server
@ -22,7 +22,8 @@ logging.basicConfig(level=logging.INFO)
def lease_to_client(lease: DhcpLease) -> DhcpClient:
return DhcpClient(
hw_address = bytes.fromhex(lease.hwaddr.replace(':', '')),
last_seen = datetime.utcfromtimestamp(lease.atime).isoformat(),
last_seen = datetime.utcfromtimestamp(lease.atime).replace(
tzinfo=timezone.utc).isoformat(),
client_hostname = lease.name,
ip_address = lease.ip
)

View File

@ -1,7 +1,7 @@
import json
import sqlite3
from pathlib import Path
from datetime import datetime
from datetime import datetime, timezone
from typing import NamedTuple, Iterable, Iterator, List
from functools import wraps
from flask import Flask, render_template, abort, g, \
@ -112,8 +112,13 @@ def app(instance_path, devices_api, config):
@app.template_filter('strfts')
def strfts(ts, format='%d/%m/%Y %H:%M'):
return datetime.fromtimestamp(ts).strftime(format)
def strfts(ts, format='%Y-%m-%d %H:%M'):
return datetime.utcfromtimestamp(ts).strftime(format)
@app.template_filter('utcisoformat')
def utcisoformat(ts):
return datetime.utcfromtimestamp(ts).replace(
tzinfo=timezone.utc).isoformat()
@app.template_filter('wikiurl')