Bug #63940 [Opn->Fbk]: DateTime->modify(last day of ) not working properly for December
Edit report at https://bugs.php.net/bug.php?id=63940&edit=1
ID: 63940
Updated by: cmb@php.net
Reported by: carlos dot jimene dot guirao at gmail dot com
Summary: DateTime->modify(last day of ) not working properly
for December
-Status: Open
+Status: Feedback
Type: Bug
Package: Date/time related
Operating System: Ubuntu 10.04.4 LTS
PHP Version: 5.3.20
Block user comment: N
Private report: N
New Comment:
This issue might dependent on the timezone. Which one do you have
set, Carlos?
var_dump(ini_get('date.timezone'));
Previous Comments:
------------------------------------------------------------------------
[2015-04-20 03:29:54] pasindu@php.net
http://3v4l.org/6PJ9o#v530
Output for hhvm-3.5.0 - 3.6.1
string(10) "2012-12-01"
string(10) "2012-12-31"
Output for 5.3.6 - 5.6.8, php7@20140507 - 20150401
string(10) "2012-12-31"
string(10) "2012-12-31"
Output for 5.3.0 - 5.3.5
string(10) "2015-04-30"
string(10) "2012-12-31"
* 5.3 is eol and seems to work on current versions
------------------------------------------------------------------------
[2013-01-08 15:37:41] carlos dot jimenez dot guirao at gmail dot com
In php version PHP 5.4.6
OS: Ubuntu 12.10
Same script outputs:
string(10) "2012-12-31"
string(10) "2012-12-31"
Results working as expected.
------------------------------------------------------------------------
[2013-01-08 15:32:24] carlos dot jimene dot guirao at gmail dot com
Description:
------------
Working with DateTime object as shown on manual.
If you modify a DateTime object using this relative format "last day of December Year" it
fails giving instead last day of next January.
It seems that it was corrected when used in DateTime Constructor instead. So if you create DateTime
object using same string in constructor it works.
Test script:
---------------
$datetime = new DateTime();
$datetime->modify('last day of December 2012');
var_dump($datetime->format('Y-m-d'));
$anotherdt = new DateTime('last day of December 2012');
var_dump($anotherdt->format('Y-m-d'));
Expected result:
----------------
string(10) "2012-12-31"
string(10) "2012-12-31"
Actual result:
--------------
string(10) "2013-01-31"
string(10) "2012-12-31"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63940&edit=1
Thread (5 messages)