summaryrefslogtreecommitdiff
path: root/jimbrella/admin.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-02-03 20:52:10 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-02-03 20:52:10 +0800
commit15dd33f6b1db117716e16f1dfee281efd9b43a2a (patch)
tree0ded11374cf1db3c5e89b7e47f8265c10d1cb3c3 /jimbrella/admin.py
parent0689f7616fd941d8b8795880f0b30676cd85dbf9 (diff)
Fix datetime format on web admin console
Diffstat (limited to 'jimbrella/admin.py')
-rw-r--r--jimbrella/admin.py11
1 files changed, 5 insertions, 6 deletions
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"