php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75083 Undocumented: IntlDateFormatter->format also accepts DateTimeInterface
Submitted: 2017-08-17 09:01 UTC Modified: 2017-08-22 16:14 UTC
From: zimzat at zimzat dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.1.8 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zimzat at zimzat dot com
New email:
PHP Version: OS:

 

 [2017-08-17 09:01 UTC] zimzat at zimzat dot com
Description:
------------
---
From manual page: http://www.php.net/intldateformatter.format
---

As of PHP 7.1.5 IntlDateFormatter->format() accepts any DateTimeInterface object, not just DateTime.


Test script:
---------------
<?php

$datetime = new DateTimeImmutable('2017-07-13');

$prettyDateFormatter = new IntlDateFormatter('en_US', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Chicago', IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd');
$prettyDateFormatter->setPattern('MMM d yyyy');

echo 'Timestamp: ', $prettyDateFormatter->format($datetime->getTimestamp()) ?: $prettyDateFormatter->getErrorMessage(), "\n";
echo 'DateTime: ', $prettyDateFormatter->format(new DateTime('2017-07-13')) ?: $prettyDateFormatter->getErrorMessage(), "\n";
echo 'DateTimeImmutable: ', $prettyDateFormatter->format($datetime) ?: $prettyDateFormatter->getErrorMessage(), "\n";


Expected result:
----------------
PHP >= 7.1.5:
Timestamp: Jul 12 2017
DateTime: Jul 12 2017
DateTimeImmutable: Jul 12 2017

PHP < 7.1.5:
Timestamp: Jul 12 2017
DateTime: Jul 12 2017
DateTimeImmutable: datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR

PHP >= 7.1.5 has changed signature to:
datefmt_format: invalid object type for date/time (only IntlCalendar and DateTimeInterface permitted): U_ILLEGAL_ARGUMENT_ERROR

Actual result:
--------------
https://3v4l.org/0ErGG

Output for hhvm-3.18.4 - 3.21.0, 7.1.5 - 7.2.0beta2
Timestamp: Jul 12 2017
DateTime: Jul 12 2017
DateTimeImmutable: Jul 12 2017

Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.4
Timestamp: Jul 12 2017
DateTime: Jul 12 2017
DateTimeImmutable: datefmt_format: invalid object type for date/time (only IntlCalendar and DateTime permitted): U_ILLEGAL_ARGUMENT_ERROR

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-22 16:14 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=342913
Log: Fix #75083: IntlDateFormatter::format also accepts DateTimeInterface
 [2017-08-22 16:14 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2017-08-22 16:14 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1a81073412d226a2b1a78036c26b1d1f8c2b9c93
Log: Fix #75083: IntlDateFormatter::format also accepts DateTimeInterface
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC