From 48582d2aba0add0455721436c247df0cd5a531eb Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 23 Jun 2021 18:19:31 +0200 Subject: [PATCH] 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] --- ext/intl/tests/bug68471.phpt | 19 +++++++++++++++++++ ext/intl/timezone/timezone_class.cpp | 5 ++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 ext/intl/tests/bug68471.phpt diff --git a/ext/intl/tests/bug68471.phpt b/ext/intl/tests/bug68471.phpt new file mode 100644 index 0000000000000..8bc901120dff4 --- /dev/null +++ b/ext/intl/tests/bug68471.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +object(IntlDateFormatter)#1 (0) { +} diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp index b261f81f817d8..adf86fa26526a 100644 --- a/ext/intl/timezone/timezone_class.cpp +++ b/ext/intl/timezone/timezone_class.cpp @@ -176,8 +176,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, return timezone_convert_datetimezone(tzobj->type, tzobj, 0, outside_error, func); } else { - UnicodeString id, - gottenId; + UnicodeString id; UErrorCode status = U_ZERO_ERROR; /* outside_error may be NULL */ if (!try_convert_to_string(zv_timezone)) { zval_ptr_dtor_str(&local_zv_tz); @@ -204,7 +203,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, zval_ptr_dtor_str(&local_zv_tz); return NULL; } - if (timeZone->getID(gottenId) != id) { + if (*timeZone == TimeZone::getUnknown()) { spprintf(&message, 0, "%s: no such time zone: '%s'", func, Z_STRVAL_P(zv_timezone)); if (message) {