Unexpected results when comparing time instances
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the reported comparisons between timezone-aware time and datetime instances on the listed CPython versions. Trace the time and datetime comparison entry points to determine why crossing a local date changes the result, then add regression coverage showing the expected equality for equivalent absolute times.
Written by the indexing model from the issue text.
Description
Bug report
When comparing two time instances with different timezone, there are some unexpected result in some cases.
from datetime import datetime, time, timezone, timedelta
# Two time instances with the same absolute time in different time zones
t1 = time(hour = 0, tzinfo = timezone(timedelta(hours=1)))
t2 = time(hour = 7, tzinfo = timezone(timedelta(hours=8)))
print(t1 == t2) # True
# Another time instances with the same absolute time in different time zones, and local date is different
t3 = time(hour = 23, tzinfo = timezone(timedelta(hours=0)))
t4 = time(hour = 7, tzinfo = timezone(timedelta(hours=8)))
print(t3 == t4) # False, UNEXPECTED
# Two datetime instances with the same absolute time in different time zones and different local date
d1 = datetime(2022, 10, 10, hour = 23, tzinfo = timezone(timedelta(hours=0)))
d2 = datetime(2022, 10, 11, hour = 7, tzinfo = timezone(timedelta(hours=8)))
print(d1 == d2) # True, make sense
print(d1.timetz() == d2.timetz()) # False, UNEXPECTED
If two times with different timezones have the same absolute time, then thay should be equle. However, when the local dates of the two times are different, the comparison will be false even if the absolute time is the same.
As in the code above, the comparison between two datetimes has expected result, even though their local dates is different. However if we compare the time extracted from these two datetimes, the result will be false.
Your environment
- CPython versions tested on: 3.9, 3.10
- Operating system and architecture: Windows, macOS
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 558
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/cpython
-
docs pending
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
build type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
stdlib topic-email type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
🐛 Bug 🔔 Pending processing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
jumpserver/jumpserver#17584 ·