php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77701 \DateTime::createFromFormat does not set default parts
Submitted: 2019-03-06 04:11 UTC Modified: 2019-03-06 04:23 UTC
From: zerkms at zerkms dot ru Assigned:
Status: Verified Package: Date/time related
PHP Version: 7.3.2 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
2 - 1 = ?
Subscribe to this entry?

 
 [2019-03-06 04:11 UTC] zerkms at zerkms dot ru
Description:
------------
As documentation says (http://php.net/manual/en/datetime.createfromformat.php):

If format does not contain the character ! then portions of the generated time which are not specified in format will be set to the current system time.

While in php >= 7.3.0 it's not the case anymore. Date fractions are filled, but time are zeroed.

➜ docker run -v $(pwd):/app --rm php:7.2-cli php /app/dt.php
int(1551845370)
string(29) "2019-03-06T04:09:30.000+00:00"

➜ docker run -v $(pwd):/app --rm php:7.3-cli php /app/dt.php
int(1551845374)
string(29) "2019-03-06T00:00:00.000+00:00"

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

$now = \DateTime::createFromFormat('u', 0);

var_dump(time(), $now->format(\DateTime::RFC3339_EXTENDED));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-06 04:23 UTC] requinix@php.net
-Status: Open +Status: Verified
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Sep 19 09:01:24 2020 UTC