Skip to content

Commit

Permalink
pythongh-116035: Document that both tzinfo and fold are ignored in co…
Browse files Browse the repository at this point in the history
…mparisons if tzinfo is the same (pythonGH-116187)

This mostly restores information removed in c12240e (pythonGH-114749).
(cherry picked from commit 05b0490)

Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
serhiy-storchaka authored and miss-islington committed Mar 1, 2024
1 parent 8dae3fa commit eaf2b68
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,9 @@ Supported operations:
that are not also :class:`!datetime` instances, even if they represent
the same date.

If both comparands are aware, and have the same :attr:`!tzinfo` attribute,
the :attr:`!tzinfo` and :attr:`~.datetime.fold` attributes are ignored and
the base datetimes are compared.
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
attributes, the comparison acts as comparands were first converted to UTC
datetimes except that the implementation never overflows.
Expand All @@ -1207,6 +1210,9 @@ Supported operations:
as well as a :class:`!datetime` object and a :class:`!date` object
that is not also a :class:`!datetime` instance, raises :exc:`TypeError`.

If both comparands are aware, and have the same :attr:`!tzinfo` attribute,
the :attr:`!tzinfo` and :attr:`~.datetime.fold` attributes are ignored and
the base datetimes are compared.
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
attributes, the comparison acts as comparands were first converted to UTC
datetimes except that the implementation never overflows.
Expand Down Expand Up @@ -1752,8 +1758,8 @@ Naive and aware :class:`!time` objects are never equal.
Order comparison between naive and aware :class:`!time` objects raises
:exc:`TypeError`.

If both comparands are aware, and have
the same :attr:`~.time.tzinfo` attribute, the common :attr:`!tzinfo` attribute is
If both comparands are aware, and have the same :attr:`~.time.tzinfo`
attribute, the :attr:`!tzinfo` and :attr:`!fold` attributes are
ignored and the base times are compared. If both comparands are aware and
have different :attr:`!tzinfo` attributes, the comparands are first adjusted by
subtracting their UTC offsets (obtained from ``self.utcoffset()``).
Expand Down

0 comments on commit eaf2b68

Please sign in to comment.