|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-11-21 12:59 UTC] mathieu dot louafi at gmail dot com
Description:
------------
The \IntlDateFormatter constructor returns 'null' when provided a 'GMT+00:00' timezone.
The correct bevahior would be to return an instance of \IntlDateFormatter.
My guess is that the problem lies in intl-3.0.0/timezone/timezone_class.cpp at line 202-211:
if (timeZone->getID(gottenId) != id) {
[...]
return NULL;
}
The problem is that, in the specific case of 'GMT+00:00', the 'timeZone->getID(gottenId)' evaluates to 'GMT', thus the inequality is sastified.
(in PHP: IntlTimeZone::createTimeZone('GMT+0N:00')->getID() is 'GMT+0N:00' if N is not 0, and 'GMT' if N = 0)
Test script:
---------------
$dt = [new \DateTime('2015-01-01 00:00:00 +00:00'), new \DateTime('2015-01-01 00:00:00 +01:00')];
$tz = ['GMT+00:00', 'GMT+01:00'];
foreach (array_merge($dt, $tz) as $timezone) {
if ($timezone instanceof \DateTime) {
$timezone = $timezone->getTimeZone();
}
$formatter = new \IntlDateFormatter(
'fr_FR',
\IntlDateFormatter::NONE,
\IntlDateFormatter::NONE,
$timezone
);
if (is_null($formatter)) {
var_dump($timezone);
}
}
Expected result:
----------------
Nothing, as the $formatter should never be 'null'.
Actual result:
--------------
object(DateTimeZone)#3 (2) {
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
string(9) "GMT+00:00"
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 15:00:01 2025 UTC |
Commenting the lines 202-211 in intl-3.0.0/timezone/timezone_class.cpp and re-compiling the extension lead to the following behaviors of the \IntlDateFormatter constructor: - 'GMT+00:00' is considered a valid timezone (the constructor returns an \IntlDateFormatter instance as expected) - (new \DateTime('2015-01-01 00:00:00 +00:00'))−>getTimeZone() is still considered an invalid timezone (the constructor returns 'null') This partially confirms my first guess about these lines of code.