Unexpected results when comparing time instances

オープン
#98,509 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

一覧に記載された CPython バージョンで、タイムゾーン対応の time インスタンスと datetime インスタンス間について報告された比較を再現してください。time と datetime の比較エントリポイントを追跡し、ローカル日付をまたぐと結果が変わる理由を特定したうえで、同等の絶対時刻に対して期待される等価性を示す回帰テストのカバレッジを追加してください。

索引モデルが issue の本文から書いたものです。

説明

extension-modules stdlib type-bug

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
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。