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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions