Bug #79182 [Opn->Nab]: IntlDateFormatter::formatObject fails with timezone type 2

From: Date: Tue, 28 Jan 2020 14:53:15 +0000
Subject: Bug #79182 [Opn->Nab]: IntlDateFormatter::formatObject fails with timezone type 2
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225196@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79182&edit=1 ID: 79182 Updated by: cmb@php.net Reported by: _php dot net at jantvrdik dot com Summary: IntlDateFormatter::formatObject fails with timezone type 2 -Status: Open +Status: Not a bug Type: Bug Package: Date/time related Operating System: Linux PHP Version: 7.4.2 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: From the IntlDateFormatter::format docs[1]: | If a DateTime or an IntlCalendar object is passed, its timezone | is not considered. The object will be formatted using the | formaterʼs configured timezone From the IntlDateFormatter::formatObject[2] docs: | The temporary IntlDateFormatter that will be created will take | the timezone from the passed in object. The timezone database | bundled with PHP will not be used – ICU's will be used instead. | The timezone identifier used in DateTime objects must therefore | also exist in ICU's database. Z does obviously not exists in ICU's database. So this is not a bug. [1] <https://www.php.net/manual/en/intldateformatter.format.php> [2] <https://www.php.net/manual/en/intldateformatter.formatobject.php> Previous Comments: ------------------------------------------------------------------------ [2020-01-28 13:00:28] _php dot net at jantvrdik dot com Description: ------------ IntlDateFormatter::formatObject() fails when date has timezone type 2. Type 1 and 3 work fine. IntlDateFormatter::format() also works fine. Test script: --------------- <?php declare(strict_types = 1); $typeOne = new DateTimeImmutable('today', new DateTimeZone('+0000')); $typeTwo = new DateTimeImmutable('today', new DateTimeZone('Z')); $typeThree = new DateTimeImmutable('today', new DateTimeZone('UTC')); $locale = 'en'; $format = 'd. MMMM'; foreach ([$typeOne, $typeTwo, $typeThree] as $date) { var_dump($date); $formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, null, null, $format); var_dump($formatter->format($date)); var_dump(IntlDateFormatter::formatObject($date, $format, $locale)); echo "\n\n\n"; } Expected result: ---------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-01-28 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } string(11) "28. January" string(11) "28. January" object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-28 00:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } string(11) "28. January" string(11) "28. January" object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2020-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } string(11) "28. January" string(11) "28. January" Actual result: -------------- object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2020-01-28 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } string(11) "28. January" string(11) "28. January" object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2020-01-28 00:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } string(11) "28. January" bool(false) object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2020-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } string(11) "28. January" string(11) "28. January" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79182&edit=1

« previous php.bugs (#225196) next »