From a85ec372f251f9b415428399fa11f74be04b5d6c Mon Sep 17 00:00:00 2001 From: krateng Date: Fri, 10 Dec 2021 22:19:12 +0100 Subject: [PATCH] Simplified timestamp desc further --- maloja/malojatime.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 31b1bda..b9d0f78 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -486,11 +486,10 @@ def time_pad(f,t,full=False): def timestamp_desc(t,short=False): - if short: - now = datetime.datetime.now(tz=datetime.timezone.utc) + timeobj = datetime.datetime.fromtimestamp(t,tz=TIMEZONE) - difference = int(now.timestamp() - t) - timeobj = datetime.datetime.utcfromtimestamp(t) + if short: + difference = int(datetime.datetime.now().timestamp() - t) thresholds = ( (10,"just now"), @@ -503,13 +502,10 @@ def timestamp_desc(t,short=False): (math.inf,f"{timeobj.strftime('%Y')}") ) - for t,s in thresholds: - if difference < t: return s.format(sec=difference,obj=datetime.datetime.utcfromtimestamp(t)) + for t,s in thresholds: if difference < t: return s else: - timeobject = datetime.datetime.fromtimestamp(t,tz=TIMEZONE) - format = get_settings("TIME_FORMAT") - return timeobject.strftime(format) + return timeobj.strftime(get_settings("TIME_FORMAT"))