You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
datetime.datetime.__add__ does not respect fold. #74628
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-05-23.21:34:31.300>created_at=<Date2017-05-23.21:21:46.333>labels= ['3.7', 'invalid', 'type-bug', 'library']
title='datetime.datetime.__add__ does not respect fold.'updated_at=<Date2017-05-23.21:34:31.298>user='https://github.com/mrshannon'
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).
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.
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.
Activity
mrshannon commentedon May 23, 2017
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).
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.
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.
abalkin commentedon May 23, 2017
The current behavior is intentional. Please see PEP-495 for details.