php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54851 DateTime::createFromFormat, $format=='D' or $format=='l' Always Returns Today.
Submitted: 2011-05-19 00:51 UTC Modified: 2011-11-26 16:44 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phpbugs at nicholassloan dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: trunk-SVN-2011-05-18 (SVN) OS: Mac OS X
Private report: No CVE-ID: None
 [2011-05-19 00:51 UTC] 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"

Patches

php-datetime-bug54851.diff-v2 (last revision 2011-05-20 09:02 UTC by mats dot lindh at gmail dot com)
php-datetime-bug54851.diff (last revision 2011-05-19 12:58 UTC by mats dot lindh at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-19 15:00 UTC] 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-06-12 02:13 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2011-11-26 16:44 UTC] derick@php.net
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.


 [2011-11-26 16:44 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=319960
Log: - Fixed bug #54851 (DateTime::createFromFormat() doesn't interpret &quot;D&quot;).
 [2011-11-26 16:44 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2011-12-06 05:59 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=320476
Log: - Fixed test case for #54851.
- Make test case for #32555 the same for all branches.
 [2012-04-18 09:47 UTC] laruence@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=547e2409066942127308adfc002b2926ce6de6f3
Log: - Fixed bug #54851 (DateTime::createFromFormat() doesn't interpret &quot;D&quot;).
 [2012-07-24 23:38 UTC] rasmus@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=547e2409066942127308adfc002b2926ce6de6f3
Log: - Fixed bug #54851 (DateTime::createFromFormat() doesn't interpret &quot;D&quot;).
 [2013-11-17 09:34 UTC] laruence@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=547e2409066942127308adfc002b2926ce6de6f3
Log: - Fixed bug #54851 (DateTime::createFromFormat() doesn't interpret &quot;D&quot;).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC