Bug #78603 [NEW]: DateTime::createFromFormat() missing component behaviour change
From: chris dot smith at widerplan dot com
Operating system: Linux
PHP version: 7.3.10
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::createFromFormat() missing component behaviour change
Description:
------------
I'm not sure if this is a problem with the documentation or code.
The documentation states:
> 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.
When executing the following based on the documentation I'd expect the
hour, minute and seconds to be set to the current time however they are
set to the epoch.
DateTime::createFromFormat('u', '123456');
// PHP < 7.3: 2019-09-27 14:50:40.123456
// PHP >= 7.3: 2019-09-27 00:00:00.123456
Further investigation led me to discover that the following example also
contradicts the documentation and has been the case since the days of
PHP 5.3.
DateTimeImmutable::createFromFormat('s', '12');
// 2019-09-27 00:00:12.000000
// Expected (per docs): 2019-09-27 14:50:12.000000
https://3v4l.org/v2bib
I ran a git bisect to identify when the microsecond handling changed
which found: 09340ea9b9b2a06c6f1369502806640779073885
Test script:
---------------
<?php
$dt1 = DateTime::createFromFormat('u', '123456');
$dt2 = DateTime::createFromFormat('s', '25');
var_dump($dt1->format('H:i'));
var_dump($dt2->format('H:i:s'));
Expected result:
----------------
string(5) "14:29"
string(8) "14:29:25"
Actual result:
--------------
string(5) "00:00"
string(8) "00:00:25"
--
Edit bug report at https://bugs.php.net/bug.php?id=78603&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78603&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78603&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78603&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78603&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78603&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78603&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78603&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78603&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78603&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78603&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78603&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78603&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78603&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78603&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78603&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78603&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78603&r=mysqlcfg
Thread (1 message)
- chris dot smith at widerplan dot com