mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-10-06 01:37:34 +00:00
Conversations: make "yesterday/N days ago" respect calendar days and not just hours
This commit is contained in:
@@ -38,16 +38,16 @@ def relative_time(timestamp):
|
||||
elif delta < 86400:
|
||||
h = int(delta / 3600)
|
||||
return str(h)+"h ago"
|
||||
elif delta < 172800:
|
||||
return "yesterday"
|
||||
elif delta < 604800:
|
||||
d = int(delta / 86400)
|
||||
return str(d)+"d ago"
|
||||
elif delta < 2592000:
|
||||
w = int(delta / 604800)
|
||||
return str(w)+"w ago"
|
||||
else:
|
||||
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d")
|
||||
days = (datetime.fromtimestamp(now).date() - datetime.fromtimestamp(timestamp).date()).days
|
||||
if days <= 1:
|
||||
return "yesterday"
|
||||
elif days < 7:
|
||||
return str(days)+"d ago"
|
||||
elif days < 30:
|
||||
return str(days // 7)+"w ago"
|
||||
else:
|
||||
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def _format_size(size):
|
||||
|
||||
@@ -1939,13 +1939,14 @@ def pretty_date(time=False):
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
if type(time) is int:
|
||||
diff = now - datetime.fromtimestamp(time)
|
||||
then = datetime.fromtimestamp(time)
|
||||
elif isinstance(time,datetime):
|
||||
diff = now - time
|
||||
then = time
|
||||
elif not time:
|
||||
diff = now - now
|
||||
then = now
|
||||
diff = now - then
|
||||
second_diff = diff.seconds
|
||||
day_diff = diff.days
|
||||
day_diff = (now.date() - then.date()).days
|
||||
|
||||
if day_diff < 0:
|
||||
return ''
|
||||
|
||||
Reference in New Issue
Block a user