Bug #75745 [Opn]: DateTime::createFromFormat "u" specifier not interpreted correctly

From: Date: Sat, 11 Apr 2020 15:22:00 +0000
Subject: Bug #75745 [Opn]: DateTime::createFromFormat "u" specifier not interpreted correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226536@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75745&edit=1 ID: 75745 Updated by: cmb@php.net Reported by: daverandom@php.net Summary: DateTime::createFromFormat "u" specifier not interpreted correctly Status: Open Type: Bug Package: Date/time related Operating System: Any PHP Version: >=7.1.0 Block user comment: N Private report: N New Comment: FWIW, the the v specifier (milliseconds) available as of PHP 7.3.0 behaves in the same way. Previous Comments: ------------------------------------------------------------------------ [2017-12-28 20:36:05] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75745&edit=1

« previous php.bugs (#226536) next »