Edit report at https://bugs.php.net/bug.php?id=63863&edit=1
ID: 63863
Comment by: armin at fruux dot com
Reported by: brian dot feaver at sellingsource dot com
Summary: DateTime:setDate() date not used after modify("last
day of...")
Status: Open
Type: Bug
Package: Date/time related
Operating System: Mac OS X
PHP Version: 5.3.20
Block user comment: N
Private report: N
New Comment:
Besides from being able to reproduce this completely, it also happens
when using setTimestamp(), as the day keeps being 'last day of month'.
PHP version: 5.4.9
OS: Mac OS X
Test script:
------------
<?php
$date = new DateTime('2012-03-30');
$date->modify("last day of last month");
var_dump($date->format('Y-m-d')); // correctly last day of Feb
$date->setTimestamp(1327881600); // 2012-01-30
var_dump($date->format('Y-m-d')); // incorrect date
$date->modify('2012-01-30');
var_dump($date->format('Y-m-d')); // does set correct date
Previous Comments:
------------------------------------------------------------------------
[2012-12-27 18:52:32] brian dot feaver at sellingsource dot com
Description:
------------
When modifying a DateTime object with modify("last day of last month") syntax
and
followed by a setDate(), the date portion of setDate() is ignored. It modifies
the
year and the month, but continues to set the day portion to the last day of the
month.
If modify() is called with the absolute date instead of setDate(), it correctly
sets the date.
Test script:
---------------
<?php
$date = new DateTime('2012-03-30');
$date->modify("last day of last month");
var_dump($date->format('Y-m-d')); // correctly last day of Feb
$date->setDate(2012, 1, 30);
var_dump($date->format('Y-m-d')); // incorrect date
$date->modify('2012-01-30');
var_dump($date->format('Y-m-d')); // does set correct date
Expected result:
----------------
string(10) "2012-02-29"
string(10) "2012-01-30"
string(10) "2012-01-30"
Actual result:
--------------
string(10) "2012-02-29"
string(10) "2012-01-31"
string(10) "2012-01-30"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63863&edit=1