Skip to content

Commit 56c8f01

Browse files
committed
Fix #2626: Duplicate scheduled year for single day events
- Removes redundant rendering of next_time.dt_start year block inside time_tag.html for single_day events - Adds unit tests to ensure the DOM output for single day events generates the year precisely once.
1 parent 7d86d4c commit 56c8f01

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

apps/events/templates/events/includes/time_tag.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
{{ next_time.dt_start|date:"Y" }}
55
</span>
66

7-
<span id="start-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}>
8-
{{ next_time.dt_start|date:"Y" }}
9-
</span>
10-
117
{% if not next_time.all_day %}
128
{{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }}
139
{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import datetime
2+
3+
from django.template.loader import render_to_string
4+
from django.test import TestCase
5+
6+
from ..models import Event, EventLocation, Calendar
7+
8+
9+
class TimeTagTemplateTests(TestCase):
10+
def test_single_day_event_year_rendering(self):
11+
"""
12+
Verify that a single-day event does not render the year twice (Issue #2626).
13+
"""
14+
# Create a single day event in the future to trigger the year rendering condition
15+
future_year = datetime.date.today().year + 1
16+
17+
calendar = Calendar.objects.create(name="Test Calendar")
18+
19+
event = Event.objects.create(
20+
title="Single Day Future Event",
21+
description="Test event",
22+
calendar=calendar,
23+
)
24+
25+
# Manually create the next_time context object
26+
class MockTime:
27+
def __init__(self):
28+
self.dt_start = datetime.datetime(future_year, 5, 25, 12, 0)
29+
self.dt_end = datetime.datetime(future_year, 5, 25, 14, 0)
30+
self.single_day = True
31+
self.all_day = False
32+
self.valid_dt_end = True
33+
34+
context = {
35+
"next_time": MockTime(),
36+
"scheduled_start_this_year": False, # Event is in the future year
37+
"scheduled_end_this_year": False,
38+
"object": event,
39+
}
40+
41+
rendered = render_to_string("events/includes/time_tag.html", context)
42+
43+
# The year should only appear visibly once in the output (not counting the datetime ISO tag).
44+
year_str = str(future_year)
45+
# Using string splitting to exclude the `datetime="2027...` occurrence by checking how many times
46+
# it appears wrapped with whitespace or inside a span.
47+
visible_occurrences = rendered.split(">\n " + year_str + "\n </span>")
48+
self.assertEqual(
49+
len(visible_occurrences) - 1,
50+
1,
51+
f"Expected the visible span containing {year_str} to appear exactly once, but it was duplicated: {rendered}"
52+
)

0 commit comments

Comments
 (0)