From a61ca162b03b1cfed78f93daead94f974bbff1d5 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 14 Sep 2024 14:33:02 +1000 Subject: [PATCH 1/5] Fix post dates being inconsistent Makes all dates fixed except if in the last day, in which case they are relative times. Fixes #3365 --- bookwyrm/templatetags/status_display.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templatetags/status_display.py b/bookwyrm/templatetags/status_display.py index c92b1877a5..c0ab406898 100644 --- a/bookwyrm/templatetags/status_display.py +++ b/bookwyrm/templatetags/status_display.py @@ -60,7 +60,7 @@ def get_published_date(date): delta = relativedelta(now, date) if delta.years: return naturalday(date) - if delta.days: + if delta.days or delta.months: return naturalday(date, "M j") return naturaltime(date) From dd45823790005bd75e0e31c264884cce05384f3b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 18 Sep 2024 19:40:44 +1000 Subject: [PATCH 2/5] enable localised dates --- bookwyrm/templatetags/status_display.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templatetags/status_display.py b/bookwyrm/templatetags/status_display.py index c0ab406898..5d1f86caf2 100644 --- a/bookwyrm/templatetags/status_display.py +++ b/bookwyrm/templatetags/status_display.py @@ -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 @@ -61,7 +62,7 @@ def get_published_date(date): if delta.years: return naturalday(date) if delta.days or delta.months: - return naturalday(date, "M j") + return naturalday(date, settings.MONTH_DAY_FORMAT) return naturaltime(date) From bee9dafc9dd4df436cc69416ca195f4654877c16 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 18 Sep 2024 19:51:43 +1000 Subject: [PATCH 3/5] update tests --- bookwyrm/tests/templatetags/test_status_display.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index 338c304816..169243c0db 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -109,4 +109,4 @@ 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") From 6745a9a3f528c5ab2db24aa63522fa9cbe3f9301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= <73768+dato@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:38:33 +0200 Subject: [PATCH 4/5] Add test for #3365 fix (#5) --- bookwyrm/tests/templatetags/test_status_display.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index 169243c0db..e62b75f371 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -110,3 +110,11 @@ def test_get_published_date(self, *_): ) result = status_display.get_published_date(date) 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") From 514c54f30a6f101fdb0f097a10a3fd1f8c72b168 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Thu, 19 Sep 2024 19:46:03 +1000 Subject: [PATCH 5/5] black formatting --- bookwyrm/tests/templatetags/test_status_display.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index e62b75f371..de7d3ae2fe 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -114,7 +114,12 @@ def test_get_published_date(self, *_): 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 + 2022, + 3, + 1, + 0, + 0, + tzinfo=datetime.timezone.utc, ) result = status_display.get_published_date(date) self.assertEqual(result, "January 1")