Skip to content

Fix statistics hang on DST fall-back day - #24

Closed
mschlicht-tt wants to merge 1 commit into
exdatic:mainfrom
mschlicht-tt:fix/21-year-statistics-dst-hang
Closed

mschlicht-tt wants to merge 1 commit into
exdatic:mainfrom
mschlicht-tt:fix/21-year-statistics-dst-hang

Conversation

@mschlicht-tt

Copy link
Copy Markdown

Fixes #21

Problem

split_into_days advanced by a fixed 24 hours and then rounded down to the start of the day. On a 25-hour day (end of daylight saving time, e.g. 25 October 2026 in Europe/Berlin), 00:00 + 24h is 23:00 on the same day, which rounds back to 00:00. The cursor never moved, so the loop ran forever and the result list kept growing. That's the 100% CPU, the growing memory, and the Streamlit server freezing for everyone.

Any range containing such a day was affected: Year always, Month only in October (the "got stuck on one month once" from the report). The spring transition (23-hour day) was harmless, and that was the only case the existing tests covered.

Fix

Step by calendar date instead and take each boundary from day_range(day + 1), the same approach get_range already uses for LAST. The now-unused DAY_MS import is removed.

Tests

  • New test_split_into_days_handles_dst_fall_back (with and without a start-of-day shift): October 2026 has 31 days, 25 October is 25 hours long, 2026 has 365 days.
  • Like the existing DST test it needs time.tzset, so it is skipped on Windows and runs in CI. Its assertions were checked by hand on a Windows machine set to Berlin time.
  • Against the old code the test hangs rather than fails, since there is no timeout plugin.
  • pytest: 119 passed, 11 skipped. flake8: clean.

Who to blame

Claude Code did this whole thing on its own: the investigation, the reproduction, the fix, the tests and this description. @mschlicht-tt only asked for it and takes no responsibility for any mischief in here. If something is wrong, blame the bot.

🤖 Generated with Claude Code

split_into_days advanced by a fixed 24 hours and then rounded down to the
start of the day. On a 25-hour day (end of daylight saving time, e.g.
25 October 2026 in Europe/Berlin) that landed on the same day again, so the
loop never ended and kept growing the result list. Any range containing such
a day hung: Year always, Month in October.

Step by calendar date instead, like get_range does for LAST.

Fixes #21

Co-Authored-By: Claude <noreply@anthropic.com>
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.

Statistics never loads when I pick Year

1 participant