php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68471 \IntlDateFormatter considers "GMT+00:00" an invalid timezone
Submitted: 2014-11-21 12:59 UTC Modified: 2021-06-23 15:28 UTC
Votes:3
Avg. Score:4.0 ± 1.4
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: mathieu dot louafi at gmail dot com Assigned: cmb (profile)
Status: Closed Package: intl (PECL)
PHP Version: 5.6.3 OS: Ubuntu 13.10
Private report: No CVE-ID: None
 [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"

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-21 13:17 UTC] mathieu dot louafi at gmail dot com
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.
 [2021-06-23 15:28 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-06-23 15:28 UTC] cmb@php.net
I agree that it doesn't make sense to reject the timezone when
passed to IntlDateFormatter::__construct(), but to allow it for
IntlTimeZone::createTimeZone().
 [2021-06-23 16:25 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #68471: IntlDateFormatter fails for "GMT+00:00" timezone
On GitHub:  https://github.com/php/php-src/pull/7190
Patch:      https://github.com/php/php-src/pull/7190.patch
 [2021-06-28 11:58 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/php-src/commit/1a01f7816c1d0d6a4d9a9b3337a792963420cbeb
Log: Fix #68471: IntlDateFormatter fails for "GMT+00:00" timezone
 [2021-06-28 11:58 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 15:01:28 2024 UTC