Skip to content

Compare of datetime.time ignores tz microseconds #99772

Description

@blenq

Bug report

Compare operations of datetime.time values ignore microseconds in timezone offsets. These operations might return wrong results in the rare event that timezone offsets contain microseconds.

Show case:

>>> from datetime import time, timedelta, timezone
>>> time(13, 12, tzinfo=timezone(timedelta(microseconds=2))) == time(13, 12, tzinfo=timezone(timedelta()))
True
>>> time(13, 12, tzinfo=timezone(timedelta(seconds=2))) == time(13, 12, tzinfo=timezone(timedelta()))
False

Both statements should return False.

Your environment

  • CPython versions tested on:
    Python 3.7.15, 3.10.8, 3.11.0, 3.12.0a2 locally compiled
    Python 3.8.10, 3.9.5 from Ubuntu repo

  • Operating system and architecture:
    Ubuntu 20.04.5 (amd64)

Patch is on the way

Linked PRs

Activity

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

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions