php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77701 \DateTime::createFromFormat does not set default parts
Submitted: 2019-03-06 04:11 UTC Modified: 2022-05-20 14:52 UTC
From: zerkms at zerkms dot ru Assigned:
Status: Closed Package: Date/time related
PHP Version: 7.3.2 OS: linux
Private report: No CVE-ID: None
 [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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-06 04:23 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2022-05-20 14:52 UTC] derick@php.net
-Type: Bug +Type: Documentation Problem
 [2022-05-20 14:52 UTC] derick@php.net
I am marking this as Documentation Problems, as this behaviour is now long standing, and not only applicable for the 'u' character. The same behaviour occurs for other time related characters too.

We can break this behaviour again, but I am not really willing to do so.
 [2022-06-02 15:52 UTC] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/e5373bc7610639edca743a5d190e78e6cf41b42f
Log: Fixed bug #77701: DateTime::createFromFormat does not set default parts
 [2022-06-02 15:52 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 14 05:01:29 2024 UTC