Wrong DateInterval when going from summer time to winter time
オープン
まだ誰も着手していません。
Bug
Extension: date
Status: Verified
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Europe/Paris の夏時間から冬時間への移行について、提供されている DateTimeImmutable::diff の再現を実行し、冬時間から夏時間へのケースと比較します。DateTimeImmutable::diff の動作と、関連する DateTimeZone のオフセット処理を追跡します。インターバルが記載された期待出力と一致し、移行ケースが引き続き正しいことが完了条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100