From 06b15c08c1b78adf9e26eb738b7a3964199989f1 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 20 Oct 2021 16:31:16 +0800 Subject: Add page /admin/umbrellas Lists all umbrellas in a table. --- jimbrella/utils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'jimbrella/utils.py') 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 -- cgit v1.2.3