diff --git a/bookwyrm/templatetags/date_ext.py b/bookwyrm/templatetags/date_ext.py index 6dc320bed..ae2690321 100644 --- a/bookwyrm/templatetags/date_ext.py +++ b/bookwyrm/templatetags/date_ext.py @@ -17,7 +17,7 @@ def naturalday_partial(date, arg=None): """ django_formats = ("DATE_FORMAT", "SHORT_DATE_FORMAT", "YEAR_MONTH_FORMAT") if not isinstance(date, PartialDate): - return defaultfilters.date(date, arg) + return naturalday(date, arg) if arg is None: arg = "DATE_FORMAT" if date.has_day: diff --git a/bookwyrm/tests/templatetags/test_date_ext.py b/bookwyrm/tests/templatetags/test_date_ext.py index f7ea73891..ebeb82907 100644 --- a/bookwyrm/tests/templatetags/test_date_ext.py +++ b/bookwyrm/tests/templatetags/test_date_ext.py @@ -2,9 +2,15 @@ from dateutil.parser import isoparse from django.test import TestCase, override_settings +from django.utils import timezone from bookwyrm.templatetags import date_ext -from bookwyrm.utils.partial_date import MonthParts, YearParts, from_partial_isoformat +from bookwyrm.utils.partial_date import ( + MonthParts, + PartialDate, + YearParts, + from_partial_isoformat, +) @override_settings(LANGUAGE_CODE="en-AU") @@ -60,3 +66,14 @@ class PartialDateTags(TestCase): self.assertEqual( "December.31", date_ext.naturalday_partial(self._partial_year, "F.j") ) + + def test_natural_format(self): + """today and yesterday are handled correctly""" + today = timezone.now() + today_date = today.date() + today_exact = PartialDate.from_datetime(today) + + # exact dates can be naturalized + self.assertEqual("today", date_ext.naturalday_partial(today)) + self.assertEqual("today", date_ext.naturalday_partial(today_date)) + self.assertEqual("today", date_ext.naturalday_partial(today_exact))