Skip to content

Commit

Permalink
Fix error when rendering dates for events
Browse files Browse the repository at this point in the history
They were coming out as `%s`.
  • Loading branch information
philgyford committed Dec 19, 2023
1 parent b1f2e21 commit e0dabb4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spectator/events/templatetags/spectator_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def display_date(d):
stamp = d.strftime("%Y-%m-%d")
visible_date = d.strftime(app_settings.DATE_FORMAT)

return format_html('<time datetime="%s">%s</time>', stamp, visible_date)
return format_html('<time datetime="{}">{}</time>', stamp, visible_date)


@register.inclusion_tag("spectator_events/includes/event_list_tabs.html")
Expand Down
17 changes: 17 additions & 0 deletions tests/events/test_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime, timezone

from django.test import TestCase

from spectator.core.factories import IndividualCreatorFactory
Expand All @@ -16,6 +18,7 @@
annual_event_counts,
day_events,
day_events_card,
display_date,
event_list_tabs,
events_years,
events_years_card,
Expand Down Expand Up @@ -58,6 +61,20 @@ def test_kind(self):
self.assertEqual(qs[1], {"year": make_date("2018-01-01"), "total": 1})


class DisplayDateTestCase(TestCase):
def test_date(self):
d = make_date("2023-12-09")
self.assertEqual(
display_date(d), '<time datetime="2023-12-09">9 Dec 2023</time>'
)

def test_datetime(self):
dt = datetime(2023, 12, 9, 13, 30, 00).astimezone(timezone.utc)
self.assertEqual(
display_date(dt), '<time datetime="2023-12-09">9 Dec 2023</time>'
)


class EventListTabsTestCase(TestCase):
def test_result(self):
counts = {"all": 30, "gig": 12, "movie": 18}
Expand Down

0 comments on commit e0dabb4

Please sign in to comment.