php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80995 Europe DateTimeZone bug in specific DateTime interval
Submitted: 2021-04-27 13:33 UTC Modified: 2021-05-05 15:37 UTC
From: loic dot geny at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 7.4.16 OS: Ubuntu 20.04.2 LTS
Private report: No CVE-ID: None
 [2021-04-27 13:33 UTC] loic dot geny at gmail dot com
Description:
------------
IntlTimeZone::createTimeZone('Europe/Paris')->toDateTimeZone();

With date between 1940/01/01 and 1940/06/14, apply the DateTimeZone don't output the correct DateTimeImmutable::format('Y-m-d)

Test script:
---------------
$timeZone = IntlTimeZone::createTimeZone('Europe/Paris')->toDateTimeZone();
$date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s','1940-06-13 23:00:00');
$timeZonedDate = $date->setTimeZone($timeZone);
echo $timeZonedDate->format('Y-m-d');

$date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s','1940-06-14 23:00:00');
$timeZonedDate = $date->setTimeZone($timeZone);
echo $timeZonedDate->format('Y-m-d');

Expected result:
----------------
Expected result : 
'1940-06-14'
'1940-06-15'

Actual result:
--------------
Current result : 
'1940-06-13'
'1940-06-15'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-27 14:56 UTC] derick@php.net
-Status: Open +Status: Feedback
 [2021-04-27 14:56 UTC] derick@php.net
What is date.timezone set to? Please add that to your reproduce script.
 [2021-04-28 08:26 UTC] loic dot geny at gmail dot com
-Status: Feedback +Status: Open
 [2021-04-28 08:26 UTC] loic dot geny at gmail dot com
It's hard to reproduce because I'm working on Symfony. My DateTimeImmutable has date.timezone_type = 1
date.timezone = "+00:00"

But here is a more accuracte sample of what is my "state" when the bug occures :

$timeZoneTl = IntlTimeZone::createTimeZone('Europe/Paris')->toDateTimeZone();
$dateT = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '1940-06-13 22:00:00', new DateTimeZone('Etc/GMT-0'));
$timeZonedDateT = $dateT->setTimezone($timeZoneTl);
echo $timeZonedDateT->format('Y-m-d');

Output : 13/06/1940 (wrong)

$timeZoneTl = IntlTimeZone::createTimeZone('Europe/Paris')->toDateTimeZone();
$dateT = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '1940-06-15 22:00:00', new DateTimeZone('Etc/GMT-0'));
$timeZonedDateT = $dateT->setTimezone($timeZoneTl);
echo $timeZonedDateT->format('Y-m-d');

Output : 15/06/1940 (correct)
 [2021-04-28 08:27 UTC] loic dot geny at gmail dot com
I'm sorry because I cannot reproduce the bug in a PHP sandbox, I'm still a noob in pure PHP ...
 [2021-04-28 08:30 UTC] loic dot geny at gmail dot com
We cant edit comment ? Sorry (again) , but the correct output is :

$timeZoneTl = IntlTimeZone::createTimeZone('Europe/Paris')->toDateTimeZone();
$dateT = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '1940-06-15 22:00:00', new DateTimeZone('Etc/GMT-0'));
$timeZonedDateT = $dateT->setTimezone($timeZoneTl);
echo $timeZonedDateT->format('Y-m-d');

Output : 16/06/1940 (correct)
 [2021-04-30 15:16 UTC] cmb@php.net
Derick is referring to the date.timezone in php.ini.  What output
does running the following script produce?

<?php
var_dump(ini_get("date.timezone"));
var_dump(date_default_timezone_get());
?>
 [2021-05-05 15:37 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-05-05 15:37 UTC] cmb@php.net
See <https://3v4l.org/q9cXH> for a reproducer which avoids the Etc
timezone, IntlTimeZone, and also prints the time.  The results are
expected, since on June, 14th there was a Time Zone Change[1].

[1] <https://www.timeanddate.com/time/change/france/paris?year=1940>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC