Edit report at http://bugs.php.net/bug.php?id=54851&edit=1

 ID:                 54851
 Comment by:         mats dot lindh at gmail dot com
 Reported by:        phpbugs at nicholassloan dot com
 Summary:            DateTime::createFromFormat, $format=='D' or
                     $format=='l' Always Returns Today.
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Mac OS X
 PHP Version:        trunk-SVN-2011-05-18 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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 http://bugs.php.net/bug.php?id=54851&edit=1

Reply via email to