php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80057 DateTimeImmutable::createFromFormat() does not populate time
Submitted: 2020-09-04 10:16 UTC Modified: -
From: bc at benjamin-cremer dot de Assigned:
Status: Closed Package: Date/time related
PHP Version: 8.0.0beta3 OS: linux
Private report: No CVE-ID: None
 [2020-09-04 10:16 UTC] bc at benjamin-cremer dot de
Description:
------------
The current time is not populated when a DateTime object is created by createFromFormat with a format pattern that has no time part defined.


Given the following code:
var_dump(DateTimeImmutable::createFromFormat('Y-m-d', '2020-09-04'));

Output from 8.0.0beta2 and before:
object(DateTimeImmutable)#1 (3) {
  ["date"]=>
  string(26) "2020-09-04 10:28:48.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

Output from 8.0.0beta3:
object(DateTimeImmutable)#1 (3) {
  ["date"]=>
  string(26) "2020-09-04 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

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

var_dump(DateTimeImmutable::createFromFormat('Y-m-d', '2020-09-04')->format('His') > 0);

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-04 14:55 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2ee2335249d4bbeed27d60a59245a966d0580074
Log: Fixed bug #80057 (DateTimeImmutable::createFromFormat() does not populate time)
 [2020-09-04 14:55 UTC] derick@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC