Wrong DateInterval when going from summer time to winter time
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
Description
The following code:
<?php
$timezone = new \DateTimeZone('Europe/Paris');
$periodStart = (new \DateTimeImmutable('2024-10-21'))->setTimezone($timezone)->setTime(00, 00, 00);
$periodEnd = (new \DateTimeImmutable('2024-10-27'))->setTimezone($timezone)->setTime(23, 59, 59);
var_dump($periodStart);
var_dump($periodEnd);
var_dump($timezone->getOffset($periodStart));
var_dump($timezone->getOffset($periodEnd));
var_dump($periodStart->diff($periodEnd)->format('%y years %m months %a days %H hours %I minutes %s seconds'));
Resulted in this output:
object(DateTimeImmutable)#2 (3) {
["date"]=>
string(26) "2024-10-21 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(12) "Europe/Paris"
}
object(DateTimeImmutable)#3 (3) {
["date"]=>
string(26) "2024-10-27 23:59:59.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(12) "Europe/Paris"
}
int(7200) // UTC+2
int(3600) // UTC+1
string(54) "0 years 0 months 6 days 23 hours 59 minutes 59 seconds"
But I expected this output instead:
object(DateTimeImmutable)#2 (3) {
["date"]=>
string(26) "2024-10-21 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(12) "Europe/Paris"
}
object(DateTimeImmutable)#3 (3) {
["date"]=>
string(26) "2024-10-27 23:59:59.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(12) "Europe/Paris"
}
int(7200)
int(3600)
string(54) "0 years 0 months 7 days 0 hours 59 minutes 59 seconds"
I did the same test using winter to summer time switch and the result is good.
<?php
$timezone = new \DateTimeZone('Europe/Paris');
$periodStart = (new \DateTimeImmutable('2024-03-25'))->setTimezone($timezone)->setTime(00, 00, 00);
$periodEnd = (new \DateTimeImmutable('2024-03-31'))->setTimezone($timezone)->setTime(23, 59, 59);
var_dump($periodStart);
var_dump($periodEnd);
var_dump($timezone->getOffset($periodStart));
var_dump($timezone->getOffset($periodEnd));
var_dump($periodStart->diff($periodEnd)->format('%y years %m months %a days %H hours %I minutes %s seconds'));
Output:
object(DateTimeImmutable)#2 (3) {
["date"]=>
string(26) "2024-03-25 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(12) "Europe/Paris"
}
object(DateTimeImmutable)#3 (3) {
["date"]=>
string(26) "2024-03-31 23:59:59.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(12) "Europe/Paris"
}
int(3600)
int(7200)
string(54) "0 years 0 months 6 days 22 hours 59 minutes 59 seconds"
3v4l.org links:
- Winter time to summer time: https://3v4l.org/AbF3B#v8.2.21 (good interval)
- Summer time to winter time: https://3v4l.org/5dsek#v8.2.21 (bad interval)
- Without DST transition: https://3v4l.org/eCGdj#v8.2.21 (same interval as summer to winter)
PHP Version
PHP 8.2.21 and up
Operating System
No response
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
Bắt đầu bằng cách chạy bản tái hiện DateTimeImmutable::diff được cung cấp cho quá trình chuyển từ mùa hè sang mùa đông ở Europe/Paris và so sánh với trường hợp chuyển từ mùa đông sang mùa hè. Theo dõi hành vi của DateTimeImmutable::diff và cách xử lý offset liên quan của DateTimeZone; được xem là hoàn thành khi khoảng thời gian khớp với đầu ra mong đợi đã nêu và các trường hợp chuyển đổi vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- 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