mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Simplified timestamp desc further
This commit is contained in:
parent
05460f97b7
commit
a85ec372f2
@ -486,11 +486,10 @@ def time_pad(f,t,full=False):
|
|||||||
|
|
||||||
def timestamp_desc(t,short=False):
|
def timestamp_desc(t,short=False):
|
||||||
|
|
||||||
if short:
|
timeobj = datetime.datetime.fromtimestamp(t,tz=TIMEZONE)
|
||||||
now = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
||||||
|
|
||||||
difference = int(now.timestamp() - t)
|
if short:
|
||||||
timeobj = datetime.datetime.utcfromtimestamp(t)
|
difference = int(datetime.datetime.now().timestamp() - t)
|
||||||
|
|
||||||
thresholds = (
|
thresholds = (
|
||||||
(10,"just now"),
|
(10,"just now"),
|
||||||
@ -503,13 +502,10 @@ def timestamp_desc(t,short=False):
|
|||||||
(math.inf,f"{timeobj.strftime('%Y')}")
|
(math.inf,f"{timeobj.strftime('%Y')}")
|
||||||
)
|
)
|
||||||
|
|
||||||
for t,s in thresholds:
|
for t,s in thresholds: if difference < t: return s
|
||||||
if difference < t: return s.format(sec=difference,obj=datetime.datetime.utcfromtimestamp(t))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
timeobject = datetime.datetime.fromtimestamp(t,tz=TIMEZONE)
|
return timeobj.strftime(get_settings("TIME_FORMAT"))
|
||||||
format = get_settings("TIME_FORMAT")
|
|
||||||
return timeobject.strftime(format)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user