Bug #73269 [Opn->Nab]: DateTime::create_from_format treats d like j for day which is inconsistent
| From: | derick@php.net | Date: | Sun, 12 Feb 2017 17:56:32 +0000 |
| Subject: | Bug #73269 [Opn->Nab]: DateTime::create_from_format treats d like j for day which is inconsistent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207286@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73269&edit=1
ID: 73269
Updated by: derick@php.net
Reported by: contactme at antonydandrea dot com
Summary: DateTime::create_from_format treats d like j for day
which is inconsistent
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Ubuntu 16.04.2
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is by design, and documented on the createFromFormat page: http://php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-parameters
Previous Comments:
------------------------------------------------------------------------
[2016-10-08 11:39:22] contactme at antonydandrea dot com
Made title clearer
------------------------------------------------------------------------
[2016-10-08 11:33:07] contactme at antonydandrea dot com
Description:
------------
In the documentation, 'd' for dates is supposed to be a 2 digit character. So if it is
less than 10, there is a 0 in front, e.g. 09.
DateTime::createfromformat is supposed to "Parses a time string according to a specified
format" return false on failure. I would expect 'd' to reject strings that did not
have two characters for strings.
Yet it seems to accept it as valid like 'j'. It looks like PHP tries to be clever and
automatically treat is as 'j', but I think this behaviour is inconsistent.
Test script:
---------------
$dateObj = date_create_from_format('Y-m-d', '1930-12-3');
var_dump($dateObj->format('Y-m-d');
Expected result:
----------------
I expect that for the sake of consistency, PHP returns false and fails to create an object based on
the format.
Actual result:
--------------
It returns the object and the var_dump has the string "1930-12-03".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73269&edit=1