Skip to content

datetime.datetime.__add__ does not respect fold. #74628

Closed

Description

@mrshannon
mannequin
BPO 30443
Nosy @abalkin, @mrshannon

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 = None
closed_at = <Date 2017-05-23.21:34:31.300>
created_at = <Date 2017-05-23.21:21:46.333>
labels = ['3.7', 'invalid', 'type-bug', 'library']
title = 'datetime.datetime.__add__ does not respect fold.'
updated_at = <Date 2017-05-23.21:34:31.298>
user = 'https://github.com/mrshannon'

bugs.python.org fields:

activity = <Date 2017-05-23.21:34:31.298>
actor = 'belopolsky'
assignee = 'none'
closed = True
closed_date = <Date 2017-05-23.21:34:31.300>
closer = 'belopolsky'
components = ['Library (Lib)']
creation = <Date 2017-05-23.21:21:46.333>
creator = 'mrshannon'
dependencies = []
files = []
hgrepos = []
issue_num = 30443
keywords = []
message_count = 2.0
messages = ['294285', '294286']
nosy_count = 2.0
nosy_names = ['belopolsky', 'mrshannon']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue30443'
versions = ['Python 3.6', 'Python 3.7']

Activity

  1. mrshannon commented on May 23, 2017

    mrshannonmannequin
    MannequinAuthor

    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.

  2. added
    3.7 (EOL)
    stdlib
    type-bug
    on May 23, 2017
  3. abalkin commented on May 23, 2017

    @abalkin
    Member

    The current behavior is intentional. Please see PEP-495 for details.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.7 (EOL)stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions