mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-21 17:11:06 +00:00
Merge pull request #3437 from hughrun/published_date
Fix post dates being inconsistent
This commit is contained in:
commit
14dba48415
2 changed files with 17 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue