datetime: Comparision and subtraction of datetime objects does not account for DST changes
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
The documentation of datetime ordering predicates says both that "datetime1 is considered less than datetime2 when datetime1 precedes datetime2 in time, taking into account the time zone" but also "If both comparands are aware, and have the same tzinfo attribute, the tzinfo and fold attributes are ignored"
I believe that ignoring fold, though documented, is incorrect, and contradicts the earlier "precedes ... in time" explanation of what the expression dt1 < dt2 means. If avoiding a conversion to UTC is an important performance optimization, a possibility is to continue to avoid it provided that the fold= and tzinfo= values are the same in both comparands.
>>> from datetime import datetime
>>> import zoneinfo
>>> la = zoneinfo.ZoneInfo("America/Los_Angeles")
>>> t1 = datetime.fromtimestamp(1604221200.0, tz=la)
>>> t2 = datetime.fromtimestamp(1604217660.0, tz=la)
>>> t1 < t2
True
>>> t1.timestamp() < t2.timestamp()
False
Tested on: 3.13.5, 3.15.0a2
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-146294
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện hành vi so sánh và phép trừ datetime được ghi chép, sử dụng các ví dụ zoneinfo với múi giờ America/Los_Angeles, đồng thời kiểm tra các điểm vào của phép sắp thứ tự và phép trừ của datetime.datetime. So sánh kết quả với việc sắp thứ tự timestamp và ngữ nghĩa được nêu trong tài liệu; được xem là hoàn tất khi hành vi và tài liệu thống nhất trong trường hợp DST fold, kèm theo phạm vi kiểm thử hồi quy phù hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100