From 15dd33f6b1db117716e16f1dfee281efd9b43a2a Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 3 Feb 2022 20:52:10 +0800 Subject: Fix datetime format on web admin console --- jimbrella/admin.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'jimbrella') diff --git a/jimbrella/admin.py b/jimbrella/admin.py index 60f7596..9cbf4c8 100644 --- a/jimbrella/admin.py +++ b/jimbrella/admin.py @@ -7,7 +7,7 @@ from .admin_log import AdminLog from .users import Users from .exceptions import * from .config import * -from .utils import human_timedelta, CST +from .utils import human_datetime, human_timedelta, CST bp = Blueprint("admin", __name__, url_prefix="/admin") db = Umbrellas(DATABASE_PATH) @@ -59,14 +59,13 @@ def umbrellas(): for umb in umbrellas: if umb["id"] == edit and not umb["lent_at"]: # autofill current time when admin is editing and lent_at is empty - umb["lent_at"] = datetime.now().isoformat(timespec="seconds") + umb["lent_at"] = datetime.now(tz=CST).replace(tzinfo=None).isoformat(timespec="seconds") elif umb["lent_at"]: try: - # web interface provides no timezone so UTC+8 is assumed - lent_at = isoparse(umb["lent_at"]).replace(tzinfo=CST) - umb["lent_at"] = lent_at.isoformat(timespec="seconds") + lent_at = isoparse(umb["lent_at"]) + umb["lent_at"] = human_datetime(lent_at) umb["lent_time_ago"] = ( - human_timedelta(datetime.now().astimezone(CST) - lent_at) + " ago" + human_timedelta(datetime.now(tz=CST) - lent_at) + " ago" ) except ValueError: umb["lent_at"] = "Invalid date" -- cgit v1.2.3