Skip to content

zoneinfo: wrong time difference across transition when tzinfo is equal #86191

Closed

Description

@dgrellscheid
BPO 42025
Nosy @pganssle
Files
  • fold_bug.py
  • fold_bug_1minute.py
  • spring_bug.py
  • 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 2020-10-21.18:59:20.317>
    created_at = <Date 2020-10-13.09:01:16.437>
    labels = ['invalid', 'type-bug', 'library', '3.9']
    title = 'zoneinfo: wrong time difference across transition when tzinfo is equal'
    updated_at = <Date 2020-10-21.18:59:20.316>
    user = 'https://bugs.python.org/dgrellscheid'

    bugs.python.org fields:

    activity = <Date 2020-10-21.18:59:20.316>
    actor = 'p-ganssle'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-10-21.18:59:20.317>
    closer = 'p-ganssle'
    components = ['Library (Lib)']
    creation = <Date 2020-10-13.09:01:16.437>
    creator = 'd.grellscheid'
    dependencies = []
    files = ['49514', '49516', '49517']
    hgrepos = []
    issue_num = 42025
    keywords = []
    message_count = 5.0
    messages = ['378545', '378548', '378549', '378554', '379235']
    nosy_count = 2.0
    nosy_names = ['p-ganssle', 'd.grellscheid']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42025'
    versions = ['Python 3.9']

    Activity

    1. dgrellscheid commented on Oct 13, 2020

      dgrellscheidmannequin
      MannequinAuthor

      I'm comparing two aware timestamps during a clock transition that differ only in their fold= value.

      When taking the difference of two aware timestamps with the *same* tzinfo, the fold parameter is ignored.

      A difference between two timestamps with different tzinfo works correctly, with fold taken into account.

      For the attached code I would expect all timedeltas to be the same, but I get:

      0:00:00 Oslo_1 - Oslo_0
      1:00:00 Berlin_1 - Oslo_0
      1:00:00 Oslo_1 - Berlin_0
      0:00:00 Berlin_1 - Berlin_0

    2. added
      3.9 (EOL)
      stdlib
      on Oct 13, 2020
    3. dgrellscheid commented on Oct 13, 2020

      dgrellscheidmannequin
      MannequinAuthor

      To make it clear that this issue is not covered by ...

      "Two such instances that differ only by the value of the fold attribute will not be distinguishable by any means other than an explicit access to the fold value." (PEP-495)

      I have modified the timestamps by one minute, so that they differ in more than just the fold attribute.

      All these should be 1:01:00 apart
      0:01:00 Oslo_1 - Oslo_0
      1:01:00 Berlin_1 - Oslo_0
      1:01:00 Oslo_1 - Berlin_0
      0:01:00 Berlin_1 - Berlin_0

    4. dgrellscheid commented on Oct 13, 2020

      dgrellscheidmannequin
      MannequinAuthor

      Here's a third example, without fold= involved. The spring transition also does not work when the timezone in the difference is equal:

      01:59:00 to 03:01:00 should be 2 minutes

      All these should be 0:02:00 apart
      1:02:00 Oslo_1 - Oslo_0
      0:02:00 Berlin_1 - Oslo_0
      0:02:00 Oslo_1 - Berlin_0
      1:02:00 Berlin_1 - Berlin_0

    5. changed the title [-]zoneinfo: fold not taken into account in time difference when tzinfo is equal[/-] [+]zoneinfo: wrong time difference across transition when tzinfo is equal[/+] on Oct 13, 2020
    6. changed the title [-]zoneinfo: fold not taken into account in time difference when tzinfo is equal[/-] [+]zoneinfo: wrong time difference across transition when tzinfo is equal[/+] on Oct 13, 2020
    7. dgrellscheid commented on Oct 13, 2020

      dgrellscheidmannequin
      MannequinAuthor

      OK, having read https://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html, this bizarreness is actually intended behaviour. It goes completely against my intuitive understanding of how this should come out. No additions are involved, just subtractions and equalities.

      Can we get some big warning boxes in the documentation about this? :)

    8. pganssle commented on Oct 21, 2020

      @pganssle
      Member

      Yeah, people are very confused by this, which is why I wrote that article.

      Maybe there is a place for big warnings somewhere? I have been mulling over the possibility of proposing a backwards-incompatible (though minimally so, hopefully) change to arithmetic semantics that would work well with how people think this should work, but I think any such backwards-incompatible change would be a Big Deal™, and unfortunately quite hard to warn about with a proper deprecation period.

    9. added
      type-bug
      on Oct 21, 2020
    10. added
      type-bug
      on Oct 21, 2020
    11. 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.9 (EOL)stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions