Skip to content

gh-116111: Document wall time arithmetic for datetimes sharing a tzinfo - #162816

Closed
Lenormju wants to merge 1 commit into
python:mainfrom
Lenormju:gh-116111-doc-timezone-and-wall-time-arithmetics
Closed

Lenormju wants to merge 1 commit into
python:mainfrom
Lenormju:gh-116111-doc-timezone-and-wall-time-arithmetics

Conversation

@Lenormju

@Lenormju Lenormju commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Arithmetic and comparisons on aware datetimes sharing a tzinfo ignore the UTC offset (wall time), by design (PEP 495), so results across a DST transition don't match elapsed time. This is only mentioned in the operation notes, and zoneinfo.rst says transitions are handled "with no further intervention", which suggests the opposite. This keeps coming up as bug reports (#116111, #112638, #146236, …).

This PR:

  • adds a "Wall time and absolute time semantics" section to datetime.rst, with an example of doing the arithmetic in UTC;
  • links to it from the notes on timedelta addition (1), subtraction (3), equality (4) and order comparison (5), and from zoneinfo.rst, replacing that sentence;
  • mentions fold in the subtraction note (3), and skipped times in the equality note (4), as PEP 495 specifies.

Same zone versus same tzinfo object (is) is left for a follow-up.

Thanks to @NehaJeevan for #137092, which first proposed fixing the zoneinfo.rst sentence.

See also #146236, #123487.

Docs only, so I think this can be skip news.

I used an LLM to review my work. But the research and the changes are mine, and I'm happy to explain any of it.

…a tzinfo

Add a section on wall time and absolute time semantics, with an example
of doing the arithmetic in UTC, and link to it from the datetime
operation notes and from zoneinfo.

In the subtraction and comparison notes, say that fold is ignored when
both operands share the same tzinfo object, and that skipped times are
never equal to times in another time zone.
@picnixz

picnixz commented Nov 28, 2026

Copy link
Copy Markdown
Member

What is the difference between #137092 and this PR? why do we have two PRs for the same issue?

@picnixz picnixz closed this Nov 28, 2026
@picnixz

picnixz commented Nov 28, 2026

Copy link
Copy Markdown
Member

While the other PR is stale, it's common courtesy to first ask if the OP wants to continue the work and wait for some time (say 2 weeks) before opening a PR. Maintainers also tend to work directly on stale PRs if necessary rather so that original contribution credits are retained.

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants