mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Refactored timestamp descriptions
This commit is contained in:
parent
3b8723790a
commit
05460f97b7
@ -488,22 +488,24 @@ def timestamp_desc(t,short=False):
|
|||||||
|
|
||||||
if short:
|
if short:
|
||||||
now = datetime.datetime.now(tz=datetime.timezone.utc)
|
now = datetime.datetime.now(tz=datetime.timezone.utc)
|
||||||
|
|
||||||
difference = int(now.timestamp() - t)
|
difference = int(now.timestamp() - t)
|
||||||
|
timeobj = datetime.datetime.utcfromtimestamp(t)
|
||||||
|
|
||||||
if difference < 10: return "just now"
|
thresholds = (
|
||||||
if difference < 60: return str(difference) + " seconds ago"
|
(10,"just now"),
|
||||||
difference = int(difference/60)
|
(2*60,f"{difference} seconds ago"),
|
||||||
if difference < 60: return str(difference) + " minutes ago" if difference>1 else str(difference) + " minute ago"
|
(2*60*60,f"{difference/60:.0f} minutes ago"),
|
||||||
difference = int(difference/60)
|
(2*24*60*60,f"{difference/(60*60):.0f} hours ago"),
|
||||||
if difference < 24: return str(difference) + " hours ago" if difference>1 else str(difference) + " hour ago"
|
(5*24*60*60,f"{timeobj.strftime('%A')}"),
|
||||||
difference = int(difference/24)
|
(31*24*60*60,f"{difference/(60*60*24):.0f} days ago"),
|
||||||
timeobject = datetime.datetime.utcfromtimestamp(t)
|
(12*31*24*60*60,f"{timeobj.strftime('%B')}"),
|
||||||
if difference < 5: return timeobject.strftime("%A")
|
(math.inf,f"{timeobj.strftime('%Y')}")
|
||||||
if difference < 31: return str(difference) + " days ago" if difference>1 else str(difference) + " day ago"
|
)
|
||||||
if difference < 300 or timeobject.year == now.year: return timeobject.strftime("%B")
|
|
||||||
#if difference < 300: return tim.strftime("%B %Y")
|
for t,s in thresholds:
|
||||||
|
if difference < t: return s.format(sec=difference,obj=datetime.datetime.utcfromtimestamp(t))
|
||||||
|
|
||||||
return timeobject.strftime("%Y")
|
|
||||||
else:
|
else:
|
||||||
timeobject = datetime.datetime.fromtimestamp(t,tz=TIMEZONE)
|
timeobject = datetime.datetime.fromtimestamp(t,tz=TIMEZONE)
|
||||||
format = get_settings("TIME_FORMAT")
|
format = get_settings("TIME_FORMAT")
|
||||||
|
Loading…
Reference in New Issue
Block a user