diff options
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 |