Bug #73269 [Opn]: DateTime::create_from_format treats d like j for day which is inconsistent

From: Date: Sat, 08 Oct 2016 11:39:23 +0000
Subject: Bug #73269 [Opn]: 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-204553@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
 User updated by:    contactme at antonydandrea dot com
 Reported by:        contactme at antonydandrea dot com
-Summary:            DateTime::create from format doesn't have trailing
                     0.
+Summary:            DateTime::create_from_format treats d like j for day
                     which is inconsistent
 Status:             Open
 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:

Made title clearer


Previous Comments:
------------------------------------------------------------------------
[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


Thread (3 messages)

« previous php.bugs (#204553) next »