From 272eba3bc1217d339cb1b0e23fd5aad2bee752a4 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 2 Feb 2022 23:23:15 +0800 Subject: Mostly westling timezones --- jimbrella/utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'jimbrella/utils.py') 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)) -- cgit v1.2.3