From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:26:17 +0000 (+0100) Subject: [3.12] gh-116035: Document that both tzinfo and fold are ignored in comparisons if... X-Git-Tag: v3.12.3~167 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16be4a3b93ca315d6d95a5e5dd17c81d03ed578a;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-116035: Document that both tzinfo and fold are ignored in comparisons if tzinfo is the same (GH-116187) (GH-116216) This mostly restores information removed in c12240ed28aac6494750e00143bc550c4d6d8ad1 (GH-114749). (cherry picked from commit 05b04903a14279421ecdc6522b8202822de6ebb5) Co-authored-by: Serhiy Storchaka --- diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index d38b966086a2..3a7fe4676a17 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -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. @@ -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. @@ -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()``).