-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The documentation of datetime ordering predicates says both that "datetime1 is considered less than datetime2 when datetime1 precedes datetime2 in time, taking into account the time zone" but also "If both comparands are aware, and have the same tzinfo attribute, the tzinfo and fold attributes are ignored"
I believe that ignoring fold, though documented, is incorrect, and contradicts the earlier "precedes ... in time" explanation of what the expression dt1 < dt2 means. If avoiding a conversion to UTC is an important performance optimization, a possibility is to continue to avoid it provided that the fold= and tzinfo= values are the same in both comparands.
>>> from datetime import datetime
>>> import zoneinfo
>>> la = zoneinfo.ZoneInfo("America/Los_Angeles")
>>> t1 = datetime.fromtimestamp(1604221200.0, tz=la)
>>> t2 = datetime.fromtimestamp(1604217660.0, tz=la)
>>> t1 < t2
True
>>> t1.timestamp() < t2.timestamp()
FalseTested on: 3.13.5, 3.15.0a2
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
No status