Skip to content

Commit 1a01f78

Browse files
committed
Fix #68471: IntlDateFormatter fails for "GMT+00:00" timezone
GMT+00:00 is recognized by ICU, and is normalized to GMT. There are no issues when GMT+00:00 is passed to `IntlTimeZone::createTimeZone()`, but passing it to IntlDateFormatter::__construct() causes a failure, since there is an additional check regarding the validity. While checking the validity of the result of `TimeZone::createTimeZone()`[1] is a good idea, comparing the IDs is overly restrictive. Instead we just check that the timezone is supported by ICU. [1] <https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1TimeZone.html#a35da0507b62754ffe5d8d59c19775cdb> Closes GH-7190.
1 parent 2327e3d commit 1a01f78

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PHP NEWS
1111
- Intl:
1212
. Fixed bug #72809 (Locale::lookup() wrong result with canonicalize option).
1313
(cmb)
14+
. Fixed bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone). (cmb)
1415

1516
- PCRE:
1617
. Fixed bug #81101 (PCRE2 10.37 shows unexpected result). (Anatol)

ext/intl/tests/bug68471.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl')) die("sikp intl extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$formatter = new IntlDateFormatter(
10+
'fr_FR',
11+
IntlDateFormatter::NONE,
12+
IntlDateFormatter::NONE,
13+
"GMT+00:00"
14+
);
15+
var_dump($formatter);
16+
?>
17+
--EXPECT--
18+
object(IntlDateFormatter)#1 (0) {
19+
}

ext/intl/timezone/timezone_class.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
176176
return timezone_convert_datetimezone(tzobj->type, tzobj, 0,
177177
outside_error, func);
178178
} else {
179-
UnicodeString id,
180-
gottenId;
179+
UnicodeString id;
181180
UErrorCode status = U_ZERO_ERROR; /* outside_error may be NULL */
182181
if (!try_convert_to_string(zv_timezone)) {
183182
zval_ptr_dtor_str(&local_zv_tz);
@@ -204,7 +203,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
204203
zval_ptr_dtor_str(&local_zv_tz);
205204
return NULL;
206205
}
207-
if (timeZone->getID(gottenId) != id) {
206+
if (*timeZone == TimeZone::getUnknown()) {
208207
spprintf(&message, 0, "%s: no such time zone: '%s'",
209208
func, Z_STRVAL_P(zv_timezone));
210209
if (message) {

0 commit comments

Comments
 (0)