Conversations: make "yesterday/N days ago" respect calendar days and not just hours

This commit is contained in:
Jeremy O'Brien 2026-07-14 09:12:07 -04:00
parent 193311b4e5
commit 79879c4e77
No known key found for this signature in database
2 changed files with 14 additions and 13 deletions

View file

@ -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):