Skip to content

Fix AmbiguousTimeError in contest calendar; (Issue #2476) - #2479

Open
Rishiii57 wants to merge 1 commit into
DMOJ:masterfrom
Rishiii57:fix-contest-calendar-ambiguous-time-2476
Open

Rishiii57 wants to merge 1 commit into
DMOJ:masterfrom
Rishiii57:fix-contest-calendar-ambiguous-time-2476

Conversation

@Rishiii57

Copy link
Copy Markdown

Hey team,

This fixes an AmbiguousTimeError that crashes the contest calendar view when viewing months that start during a daylight saving time fall-back transition at midnight (like /contests/2026/11/ or /contests/2020/11/ for users in the America/Havana timezone).

What was happening

ContestCalendar.get_table() calculates the calendar start and end dates with datetime.datetime.combine(calendar[0][0], time.min) and passes them to make_aware(). In timezones where DST ends right at midnight on Sunday (such as Cuba falling back from Daylight Time to Standard Time on the first Sunday of November), 00:00:00 happens twice. Because make_aware() defaults to is_dst=None, pytz cannot tell which side of the transition to pick and raises pytz.exceptions.AmbiguousTimeError.

What changed

We added a helper method _make_aware() on ContestCalendar that resolves ambiguity by setting is_dst=False when using pytz. This cleanly picks standard time for the midnight boundary during fall-back transitions without crashing. For normal dates or standard zoneinfo, it behaves exactly as before.

Testing

  • Verified with a standalone reproducer reproducing the exact crash on unpatched code and confirming clean resolution on patched code.
  • Added ContestCalendarTestCase with test_make_aware_ambiguous_dst and test_get_table_ambiguous_dst in judge/models/tests/test_contest.py.
  • Ran manage.py test across all related test suites with 18/18 passing tests.
  • Ran flake8 with 0 warnings or errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants