Skip to content

Count elapsed time across DST in timesince - #56

Merged
wolph merged 1 commit into
wolph:developfrom
pralav-25:fix-timesince-dst-elapsed-time
Oct 11, 2026
Merged

wolph merged 1 commit into
wolph:developfrom
pralav-25:fix-timesince-dst-elapsed-time

Conversation

@pralav-25

Copy link
Copy Markdown
Contributor

timesince subtracts the input from datetime.now(input.tzinfo). When both share the same changing timezone, Python ignores UTC-offset changes and fold: the two occurrences of 2026-11-01 01:30 in New York are one hour apart but currently produce just now. Across the spring transition, one elapsed hour can produce 2 hours ago.

Convert the current aware time to UTC before subtraction so elapsed time includes offset changes. Leave the input in its original timezone to preserve valid datetime.min/max values whose equivalent UTC dates would overflow. Naive datetime, timedelta and date-error behavior stay the same. Add past/future fall-back and spring-forward regressions, boundary coverage, and a short guide clarification.

Validation:

  • Four DST regressions fail against the original implementation; the two boundary cases already pass and remain covered.
  • Full tox passes on CPython 3.10–3.14 and PyPy 3.10–3.11: 348 tests per interpreter and 100% statement and branch coverage.
  • Ruff check/format, mypy, basedpyright, pyrefly, codespell, Sphinx with warnings treated as errors, isolated wheel/sdist builds and Twine checks pass.
  • Independent review verified 150 elapsed-time cases, including New York, Berlin, Lord Howe half-hour transitions and Apia's skipped day, plus six extreme date/offset cases and existing naive/date/custom-timezone behavior.

Prepared with OpenAI Codex assistance, including implementation, tests and independent review. Current and historical issues and pull requests, including the aware-datetime support in #54, were checked for duplicates.

timezone = ZoneInfo('America/New_York')
except ZoneInfoNotFoundError:
pytest.skip('IANA timezone data is not available')
current = current.replace(tzinfo=timezone)
@wolph
wolph marked this pull request as ready for review October 11, 2026 08:36
@wolph
wolph merged commit a52274d into wolph:develop Oct 11, 2026
16 of 17 checks passed
wolph added a commit that referenced this pull request Oct 11, 2026
CodeQL flagged timezone as possibly uninitialised in
test_timesince_counts_elapsed_time_across_dst, because it does not know
that pytest.skip raises. A skipif mark on the available timezones keeps
the same skip without the try block.
@wolph

wolph commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thank you for the fix and the thorough tests! DST manages to bite every time library eventually.

CodeQL didn't realise that pytest.skip raises, so I've moved the skip to a skipif mark in 08270c6.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T08:38:57.034448Z 3c0eb1d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

3 participants