ID: 47846
Updated by: [email protected]
Reported By: brooksie155 at yahoo dot com
Status: Feedback
Bug Type: Date/time related
Operating System: CentOS
PHP Version: 5.2CVS-2009-03-31 (snap)
New Comment:
The output from your script on my box:
America/Los_Angeles
array(12) {
["year"]=>
int(2009)
["month"]=>
int(2)
["day"]=>
bool(false)
["hour"]=>
bool(false)
["minute"]=>
bool(false)
["second"]=>
bool(false)
["fraction"]=>
bool(false)
["warning_count"]=>
int(0)
["warnings"]=>
array(0) {
}
["error_count"]=>
int(0)
["errors"]=>
array(0) {
}
["is_localtime"]=>
bool(false)
}
2009-03-03T00:00:00-0800
That 'false' there on the date will make it default to today's date.
Seeing it on both 5.2 and 5.3 on Freebsd.
Previous Comments:
------------------------------------------------------------------------
[2009-03-31 09:01:28] [email protected]
Just as a comment to Rasmus, that's not true. The format "2009-02"
implicitly sets the day nr as 1.
------------------------------------------------------------------------
[2009-03-31 08:56:25] [email protected]
I can not reproduce this, what does the following output:
<?php
$str = "2009-02";
echo date_default_timezone_get(), "\n";
var_dump( date_parse( $str ) );
$date = new DateTime( $str );
echo $date->format( DateTime::ISO8601 ), "\n";
?>
------------------------------------------------------------------------
[2009-03-31 08:56:02] [email protected]
Not a bug. As documented, this defaults to now and you can override
individual components in the constructor. In your case you have chosen
Feb. 2009, but didn't specify a day of the month. PHP picks todays day,
which is the 31st day of the month. The 31st day of Feb will fall in
March since Feb doesn't have 31 days.
------------------------------------------------------------------------
[2009-03-31 08:44:45] brooksie155 at yahoo dot com
Description:
------------
There is a bug in the constructor of this object if you are only
specifying the month and the year when dealing with the month of
February.
Reproduce code:
---------------
$date = new DateTime('2009-02');
echo $date->format('Y-m');
Expected result:
----------------
2009-02
Actual result:
--------------
2009-03
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47846&edit=1