Merge pull request #3437 from hughrun/published_date

Fix post dates being inconsistent
This commit is contained in:
Mouse Reeve 2024-10-17 15:39:13 -07:00 committed by GitHub
commit 14dba48415
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View file

@ -1,6 +1,7 @@
""" template filters """
from dateutil.relativedelta import relativedelta
from django import template
from django.conf import settings
from django.contrib.humanize.templatetags.humanize import naturaltime, naturalday
from django.template.loader import select_template
from django.utils import timezone
@ -60,8 +61,8 @@ def get_published_date(date):
delta = relativedelta(now, date)
if delta.years:
return naturalday(date)
if delta.days:
return naturalday(date, "M j")
if delta.days or delta.months:
return naturalday(date, settings.MONTH_DAY_FORMAT)
return naturaltime(date)

View file

@ -109,4 +109,17 @@ class StatusDisplayTags(TestCase):
2022, 1, 8, 0, 0, tzinfo=datetime.timezone.utc
)
result = status_display.get_published_date(date)
self.assertEqual(result, "Jan 1")
self.assertEqual(result, "January 1")
with patch("django.utils.timezone.now") as timezone_mock:
timezone_mock.return_value = datetime.datetime(
# bookwyrm-social#3365: bug with exact month deltas
2022,
3,
1,
0,
0,
tzinfo=datetime.timezone.utc,
)
result = status_display.get_published_date(date)
self.assertEqual(result, "January 1")