Skip to content

Determine datetime awareness from its UTC offset - #568

Closed
Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/timestamp-awareness
Closed

Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/timestamp-awareness

Conversation

@Gambit-Checkmate

@Gambit-Checkmate Gambit-Checkmate commented Oct 8, 2026 •

Copy link
Copy Markdown

The change

Determine datetime awareness through utcoffset() is not None in dt_to_timestamp, instead of tzinfo truthiness. Honor the documented UTC assumption for naive datetimes that carry tzinfo returning None, and preserve real offsets from false-valued timezone objects. Document this boundary and test microseconds, a pre-epoch value, false-valued timezone objects and standard offsets (-05:00, UTC, +05:30).

Before the fix: two new regressions fail, and three standard-offset controls pass. After it: python -m pytest --doctest-modules boltons tests -q passes 683 tests and 12 subtests on Windows/Python 3.13.13. git diff --check passes. No dependency changes or local-time assumption introduced.

The backstory

Following #551/#552 and #553/#554, this was inspected by Codex under the account owner's daily open-source contribution request. Comparing the converter with datetime's awareness definition exposed an exception and a wrong timestamp. No human production history is claimed; both failures and the regressions were run against unchanged master.

AI assistance

  • Harness/tooling: Codex, GitHub CLI, Python, pytest.
  • Model(s): OpenAI GPT-6.
  • Original prompt(s): “每天早上 8 点在本会话继续推进两个高质量的开源贡献 PR。” The task also requires at least 1,000 upstream stars, duplicate checks, real modifications, tests and verified write permissions.

Fixes #566.

Hosted checks: GitHub Actions requires maintainer approval for this external contribution (action_required): https://github.com/mahmoud/boltons/actions/runs/37705698461 . Read the Docs build is pending. Full local tests passed as reported above.

@Saadia751 Saadia751 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The utcoffset() definition handles a custom tzinfo returning None correctly. I compared naive, custom-naive and aware values against datetime.timestamp() with an explicit UTC assumption, including 1969, 2038, 2400 and offsets of −05:30 and +05:45.

Checked 6f73011197de with standalone Python 3.12.14 checks (20 passing assertions). I haven't run the full upstream suite.

mahmoud added a commit that referenced this pull request Oct 25, 2026
@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #609 (see the PR description for credit). Thanks for the report and the repro.

@mahmoud mahmoud closed this Oct 25, 2026
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.

dt_to_timestamp misclassifies custom timezone awareness

3 participants