diff options
author | Frederick Yin <fkfd@fkfd.me> | 2021-10-20 16:31:16 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2021-10-20 16:31:16 +0800 |
commit | 06b15c08c1b78adf9e26eb738b7a3964199989f1 (patch) | |
tree | b9d8a2c78112ccdd3846166e46d80a26401aa2f1 /jimbrella/utils.py | |
parent | 27c8be28e00fbf110143d4bc4b949c610f704639 (diff) |
Add page /admin/umbrellas
Lists all umbrellas in a table.
Diffstat (limited to 'jimbrella/utils.py')
-rw-r--r-- | jimbrella/utils.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/jimbrella/utils.py b/jimbrella/utils.py index fc68206..c7e8176 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,9 +1,18 @@ -from datetime import timedelta +from datetime import datetime, timedelta + + +def human_datetime(time: datetime) -> str: + return "{:%Y-%m-%d %H:%M}".format(time) def human_timedelta(delta: timedelta) -> str: + if delta.days == 0: + days = "" + elif delta.days == 1: + days = "1 day, " + else: + days = f"{delta.days} days, " + hours = delta.seconds // 3600 minutes = delta.seconds % (hours * 3600) // 60 - return ( - f"{delta.days} days, " if delta.days else "" - ) + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits + return days + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits |