Store timestamps in UTC and print in localtime
This commit is contained in:
@@ -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.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
__version__ = "1.0.0"
|
||||
__author__ = "Thomas Oettli <spacefreak@noop.ch>"
|
||||
|
||||
@@ -23,6 +25,13 @@ __all__ = [
|
||||
"server",
|
||||
]
|
||||
|
||||
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"
|
||||
|
||||
def datetime_str(datetime):
|
||||
return datetime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
def datetime_str(dt, utc=False):
|
||||
if not isinstance(dt, datetime.datetime):
|
||||
return "Never"
|
||||
|
||||
if utc:
|
||||
return timestamp.strftime(DATETIME_FORMAT)
|
||||
else:
|
||||
return timestamp.astimezone().strftime(DATETIME_FORMAT)
|
||||
|
||||
@@ -17,7 +17,7 @@ def cleanup_expired(app):
|
||||
Returns:
|
||||
Number of expired hostnames processed.
|
||||
"""
|
||||
now = datetime.now()
|
||||
now = datetime.now(datetime.timezone.utc)
|
||||
expired_count = 0
|
||||
|
||||
for hostname in Hostname.select().join(User).where(
|
||||
|
||||
@@ -316,7 +316,7 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
except ValueError:
|
||||
return (400, "badip")
|
||||
|
||||
now = datetime.now()
|
||||
now = datetime.now(datetime.timezone.utc)
|
||||
|
||||
changed = False
|
||||
if ipv4:
|
||||
|
||||
Reference in New Issue
Block a user