diff options
Diffstat (limited to 'jimbrella/utils.py')
-rw-r--r-- | jimbrella/utils.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/jimbrella/utils.py b/jimbrella/utils.py index fd2c86d..6e02d1a 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,7 +1,4 @@ -from datetime import datetime, timedelta, tzinfo - -# identity function -identity = lambda x: x +from datetime import datetime, timedelta, timezone def human_datetime(time: datetime) -> str: @@ -18,4 +15,14 @@ def human_timedelta(delta: timedelta) -> str: hours = delta.seconds // 3600 minutes = (delta.seconds - (hours * 3600)) // 60 - return days + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits + + if hours == 0 and minutes == 0: + return "<1 minute" + + if hours == 0: + return days + f"{minutes}min" + + return days + f"{hours}h {minutes}min" + + +CST = timezone(timedelta(hours=8)) |