Bug #73269 [NEW]: DateTime::create from format doesn't have trailing 0.

From: Date: Sat, 08 Oct 2016 11:33:13 +0000
Subject: Bug #73269 [NEW]: DateTime::create from format doesn't have trailing 0.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204551@lists.php.net to get a copy of this message
From:             contactme at antonydandrea dot com
Operating system: Ubuntu 16.04.2
PHP version:      7.0.11
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime::create from format doesn't have trailing 0.

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 bug report at https://bugs.php.net/bug.php?id=73269&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73269&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73269&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73269&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73269&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73269&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73269&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73269&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73269&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73269&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73269&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73269&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73269&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73269&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73269&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73269&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73269&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73269&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73269&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73269&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73269&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#204551) next »