Store timestamps in UTC and print in localtime

This commit is contained in:
2026-01-22 21:56:12 +01:00
parent 4bcd9f2a7f
commit 9c7f4dfd1a
3 changed files with 13 additions and 4 deletions

View File

@@ -5,6 +5,8 @@ A daemon that accepts HTTP(S) requests to dynamically update DNS entries.
Includes CLI administration tools for user and hostname management. Includes CLI administration tools for user and hostname management.
""" """
import datetime
__version__ = "1.0.0" __version__ = "1.0.0"
__author__ = "Thomas Oettli <spacefreak@noop.ch>" __author__ = "Thomas Oettli <spacefreak@noop.ch>"
@@ -23,6 +25,13 @@ __all__ = [
"server", "server",
] ]
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"
def datetime_str(datetime): def datetime_str(dt, utc=False):
return datetime.strftime("%Y-%m-%d %H:%M:%S") if not isinstance(dt, datetime.datetime):
return "Never"
if utc:
return timestamp.strftime(DATETIME_FORMAT)
else:
return timestamp.astimezone().strftime(DATETIME_FORMAT)

View File

@@ -17,7 +17,7 @@ def cleanup_expired(app):
Returns: Returns:
Number of expired hostnames processed. Number of expired hostnames processed.
""" """
now = datetime.now() now = datetime.now(datetime.timezone.utc)
expired_count = 0 expired_count = 0
for hostname in Hostname.select().join(User).where( for hostname in Hostname.select().join(User).where(

View File

@@ -316,7 +316,7 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
except ValueError: except ValueError:
return (400, "badip") return (400, "badip")
now = datetime.now() now = datetime.now(datetime.timezone.utc)
changed = False changed = False
if ipv4: if ipv4: