Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix post dates being inconsistent #3437

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading