Skip to content

Commit

Permalink
Merge pull request #3437 from hughrun/published_date
Browse files Browse the repository at this point in the history
Fix post dates being inconsistent
  • Loading branch information
mouse-reeve authored Oct 17, 2024
2 parents 09bbaf0 + 514c54f commit 14dba48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bookwyrm/templatetags/status_display.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)


Expand Down
15 changes: 14 additions & 1 deletion bookwyrm/tests/templatetags/test_status_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,17 @@ def test_get_published_date(self, *_):
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")

0 comments on commit 14dba48

Please sign in to comment.