Edit report at https://bugs.php.net/bug.php?id=54851&edit=1
ID: 54851 Updated by: der...@php.net Reported by: phpbugs at nicholassloan dot com Summary: DateTime::createFromFormat, $format=='D' or $format=='l' Always Returns Today. -Status: Assigned +Status: Closed Type: Bug Package: Date/time related Operating System: Mac OS X PHP Version: trunk-SVN-2011-05-18 (SVN) Assigned To: derick Block user comment: N Private report: N New Comment: This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2011-11-26 16:44:08] der...@php.net Automatic comment from SVN on behalf of derick Revision: http://svn.php.net/viewvc/?view=revision&revision=319960 Log: - Fixed bug #54851 (DateTime::createFromFormat() doesn't interpret "D"). ------------------------------------------------------------------------ [2011-05-19 15:00:59] mats dot lindh at gmail dot com The issue seems to be that there is currently no parsing done for the D/l parameters. I've added a patch and a test that seems to fix the issue. ------------------------------------------------------------------------ [2011-05-19 00:51:31] phpbugs at nicholassloan dot com Description: ------------ If the format only includes a day string ('D' or 'l'), it is ignored, and a DateTime instance for the current date/time is returned. Maybe I'm a stupid idiot, but I would expect either an error, or for it to return a DateTime object for the next occurrence of the given day (similar to \DateTime::__construct('Monday');) Test script: --------------- <?php $date = new \DateTime('tomorrow'); $date2 = \DateTime::createFromFormat('D', $date->format('D')); var_dump($date); var_dump($date->format('D')); var_dump($date2); var_dump($date2->format('D')); Expected result: ---------------- I expect the same date/day to be selected in both cases. Actual result: -------------- object(DateTime)#1 (3) { ["date"]=> string(19) "2011-05-19 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" } string(3) "Thu" object(DateTime)#2 (3) { ["date"]=> string(19) "2011-05-18 18:49:33" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" } string(3) "Wed" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=54851&edit=1