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
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: bc at benjamin-cremer dot de
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 11:03:35 2021 UTC