php / php/php-src

Wrong DateInterval when going from summer time to winter time

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

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

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:

PHP Version

PHP 8.2.21 and up

Operating System

No response

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

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

はじめの一歩

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

調査の方向性

まず、Europe/Paris の夏時間から冬時間への移行について、提供されている DateTimeImmutable::diff の再現を実行し、冬時間から夏時間へのケースと比較します。DateTimeImmutable::diff の動作と、関連する DateTimeZone のオフセット処理を追跡します。インターバルが記載された期待出力と一致し、移行ケースが引き続き正しいことが完了条件です。

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

評価

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

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

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