Bug #65683 [Com]: Intl does not support DateTimeImmutable

From: Date: Sun, 10 Mar 2019 04:18:09 +0000
Subject: Bug #65683 [Com]: Intl does not support DateTimeImmutable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219900@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65683&edit=1

 ID:                 65683
 Comment by:         phpweb at thax dot hardliners dot org
 Reported by:        poinsot dot julien at gmail dot com
 Summary:            Intl does not support DateTimeImmutable
 Status:             Closed
 Type:               Bug
 Package:            Date/time related
 PHP Version:        5.5.3
 Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

On PHP 7.3 Intl still does not support DateTimeImmutable with formatObject:

>>> var_dump(datefmt_format_object(date_create_immutable('1970-01-01'),
>>> 'fr_FR'));

PHP Warning:  datefmt_format_object(): datefmt_format_object: the passed object must be an instance
of either IntlCalendar or DateTime 

One still has to use the long form:

>>>
>>> var_dump(datefmt_create('fr_FR',NULL,NULL)->format(date_create_immutable('1970-01-01')));
string(42) "jeudi 1 janvier 1970 à 00:00:00 UTC+01:00"


Previous Comments:
------------------------------------------------------------------------
[2017-03-28 22:58:10] nikic@php.net

Fixed by https://github.com/php/php-src/commit/d896878ad592335ee094f531f56673178dc2b301.

------------------------------------------------------------------------
[2015-12-17 14:05:21] attila at szeremi dot org

I'm getting the issue that formatting a DateTimeImmutable with IntlDateFormatter results in an
empty string.

PHP version used: PHP 5.5.29-1~dotdeb+7.1 (cli)

------------------------------------------------------------------------
[2014-05-19 13:55:28] alan at alanpearce dot co dot uk

DateTimeZone::getOffset also doesn't accept a DateTimeImmutable object.

------------------------------------------------------------------------
[2014-03-28 16:59:59] poinsot dot julien at gmail dot com

The commit you mention seems to allow DateTimeImmutable usage with DatePeriod::__construct but still
does not fix intl stuffs.

Test script:
---------------
ini_set('intl.error_level', E_WARNING);
var_dump(
        datefmt_create('fr_FR', IntlDateFormatter::FULL,
IntlDateFormatter::FULL)->format(date_create_immutable('1970-01-01')),
        datefmt_create('fr_FR', IntlDateFormatter::FULL,
IntlDateFormatter::FULL)->format(date_create('1970-01-01'))
);

Actual result:
--------------
Warning: IntlDateFormatter::format(): datefmt_format: invalid object type for date/time (only
IntlCalendar and DateTime permitted) in %s on line %d
bool(false)
string(39) "jeudi 1 janvier 1970 00:00:00 UTC+01:00"

Expected result:
----------------
string(39) "jeudi 1 janvier 1970 00:00:00 UTC+01:00"
string(39) "jeudi 1 janvier 1970 00:00:00 UTC+01:00"

------------------------------------------------------------------------
[2014-03-27 16:09:27] phofstetter at sensational dot ch

This has been fixed in 5f09944662e09ea0b3f93cfab8702f188955e68c which is in 5.5.9 and later.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=65683


--
Edit this bug report at https://bugs.php.net/bug.php?id=65683&edit=1


Thread (8 messages)

« previous php.bugs (#219900) next »