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
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: zerkms at zerkms dot ru
New email:
PHP Version: OS:

 

 [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
 [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: Tue Mar 19 05:01:29 2024 UTC