php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75439 IntlDateFormatter's format doesn't format DateTimeImmutable date/time
Submitted: 2017-10-25 13:19 UTC Modified: 2018-05-15 16:14 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: iwanluijks at gmail dot com Assigned: ab (profile)
Status: Closed Package: intl (PECL)
PHP Version: 5.6.31 OS: CentOS 7.4.1708
Private report: No CVE-ID: None
 [2017-10-25 13:19 UTC] iwanluijks at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/intldateformatter.format
---

When an instance of \DateTimeImmutable is passed to \IntlDateFormatter's format() method, it doesn't format the date/time.

Please see the test script for a more accurate example, and check the last line of the "Actual result".

Test script:
---------------
<?php
$testDate = '2017-10-25 15:11:00';

$dateTime = \DateTime::createFromFormat('Y-m-d H:i:s', $testDate);
$dateTimeImm = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $testDate);

$formatter = new \IntlDateFormatter('nl-NL', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE);

var_dump($testDate);
var_dump($dateTime);
var_dump($formatter);
var_dump($formatter->format($dateTime));

var_dump($testDate);
var_dump($dateTimeImm);
var_dump($formatter);
var_dump($formatter->format($dateTimeImm));


Expected result:
----------------
string(19) "2017-10-25 15:11:00"
object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2017-10-25 15:11:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
object(IntlDateFormatter)#3 (0) {
}
string(24) "woensdag 25 oktober 2017"
string(19) "2017-10-25 15:11:00"
object(DateTimeImmutable)#2 (3) {
  ["date"]=>
  string(26) "2017-10-25 15:11:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
object(IntlDateFormatter)#3 (0) {
}
string(24) "woensdag 25 oktober 2017"


Actual result:
--------------
string(19) "2017-10-25 15:11:00"
object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2017-10-25 15:11:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
object(IntlDateFormatter)#3 (0) {
}
string(24) "woensdag 25 oktober 2017"
string(19) "2017-10-25 15:11:00"
object(DateTimeImmutable)#2 (3) {
  ["date"]=>
  string(26) "2017-10-25 15:11:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
object(IntlDateFormatter)#3 (0) {
}
bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-15 16:14 UTC] ab@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ab
 [2018-05-15 16:14 UTC] ab@php.net
Thanks for the report. The expected result is to see with PHP 7.1, which is the lowest actively supported branch ATM. Versions below 7.1 are security support only.

Thanks.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 04:01:24 2020 UTC