php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75745 DateTime::createFromFormat "u" specifier not interpreted correctly
Submitted: 2017-12-28 20:36 UTC Modified: 2020-04-11 15:22 UTC
From: daverandom@php.net Assigned:
Status: Open Package: Date/time related
PHP Version: >=7.1.0 OS: Any
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: daverandom@php.net
New email:
PHP Version: OS:

 

 [2017-12-28 20:36 UTC] daverandom@php.net
Description:
------------
The "u" specifier is documented as "microseconds" but is interpreted as "fraction of a second".

While this is not the correct behaviour, it is potentially a desirable behaviour, specifically one might expect to be able to interpret a date like `12:13:14.42` as having a fractional part.

I propose adding an "f" specifier (currently unused) which retains this old behaviour, and fixing "u" to work as documented.

Test script:
---------------
echo DateTime::createFromFormat('u', '42')->format('u');

Expected result:
----------------
000042

Actual result:
--------------
420000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-28 23:02 UTC] daverandom@php.net
-PHP Version: 7.1.12 +PHP Version: >=7.1.0
 [2020-04-11 15:22 UTC] cmb@php.net
FWIW, the the v specifier (milliseconds) available as of PHP 7.3.0
behaves in the same way.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Aug 09 09:01:24 2020 UTC