php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65683 Intl does not support DateTimeImmutable
Submitted: 2013-09-16 17:26 UTC Modified: 2017-03-28 22:58 UTC
Votes:10
Avg. Score:4.6 ± 0.5
Reproduced:9 of 9 (100.0%)
Same Version:4 (44.4%)
Same OS:0 (0.0%)
From: poinsot dot julien at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Date/time related
PHP Version: 5.5.3 OS:
Private report: No CVE-ID: None
 [2013-09-16 17:26 UTC] poinsot dot julien at gmail dot com
Description:
------------
Actually, DateTimeImmutable is not usable everywhere DateTime is.

Missing support I have found is:
* DatePeriod::__construct where end parameter does not allow a DateTimeImmutable objet as date_ce_date is used instead of date_ce_interface
* intl extension (see grep -rn php_date_get_date_ce ext/intl for complete list) which use the function php_date_get_date_ce (so date_ce_date)

Test script:
---------------
var_dump(datefmt_create('fr_FR')->format(date_create_immutable('1970-01-01')));

$start = new DateTimeImmutable('last monday');
var_dump(new DatePeriod($start, DateInterval::createFromDateString('1 day'), $start->add(DateInterval::createFromDateString('5 days'))));

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

object(DatePeriod)#3 (6) {
...
}

Actual result:
--------------
Warning: IntlDateFormatter::format(): datefmt_format: object must be an instance of DateTime in %s on %d

Fatal error: Uncaught exception 'Exception' with message 'DatePeriod::__construct(): This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments.' in %s:%d

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-27 16:09 UTC] phofstetter at sensational dot ch
This has been fixed in 5f09944662e09ea0b3f93cfab8702f188955e68c which is in 5.5.9 and later.
 [2014-03-28 16:59 UTC] 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-05-19 13:55 UTC] alan at alanpearce dot co dot uk
DateTimeZone::getOffset also doesn't accept a DateTimeImmutable object.
 [2015-12-17 14:05 UTC] 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)
 [2017-03-28 22:16 UTC] nikic@php.net
-Summary: Incomplete support of DateTimeImmutable as DateTime(Interface) +Summary: Intl does not support DateTimeImmutable
 [2017-03-28 22:58 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC