This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: datetime.datetime.__add__ does not respect fold.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, mrshannon
Priority: normal Keywords:

Created on 2017-05-23 21:21 by mrshannon, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg294285 - (view) Author: Michael R. Shannon (mrshannon) Date: 2017-05-23 21:21
datetime.datetime.__add__ is currently implemented by converting the date into a datetime.timedelta object (using toordinal) before adding it to the other (timedelta) object and reconstructing with datetime.combine.  With this method, fold will always be set to 0.

There are two cases that will produce an incorrect result (assuming positive timedelta for examples).

1. fold=0 and the timedelta is large enough to push the time into or past a fold.  Either fold will be 0 and not 1 as it should or the time will be too far ahead by the size of the fold.

2. fold=1 and the timedelta is small enough to leave the time in the fold but fold will be set to 0.  This results in the time being too far behind by the size of the fold.

A possible fix is to convert to UTC before adding the timedelta and call self._tzinfo.fromutc() on the result.
msg294286 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2017-05-23 21:34
The current behavior is intentional.  Please see PEP 495 for details.
History
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74628
2017-05-23 21:34:31belopolskysetstatus: open -> closed
resolution: not a bug
messages: + msg294286

stage: resolved
2017-05-23 21:21:46mrshannoncreate