diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-02-02 23:23:15 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-02-02 23:23:15 +0800 |
commit | 272eba3bc1217d339cb1b0e23fd5aad2bee752a4 (patch) | |
tree | 2969dbc45aa9eb662d8bffa8b3163d3e9e8830b7 /jimbrella/utils.py | |
parent | dd160916a8f1a9028d95d7e0344d40544078151f (diff) |
Mostly westling timezones
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)) |