ZF-10351: Zend_Date::addMonth() fails .. with Dates around midnight and timzone offset set , and certain values for month
Description
<?php
$date = new Zend_Date('2010-08-20T00:00:00+02:00', Zend_Date::ISO_8601);
echo "\n" . $date->get(Zend_Date::ISO_8601); // 2010-08-20T00:00:00+02:00
$date->addMonth(3);
echo "\n".$date->get(Zend_Date::ISO_8601); // 2010-11-01T00:00:00+02:00
?>
The day is set to one.
To reproduce : date with 00:xx:xx , fails for addMonth() with values 3,4,5,6,7
Test case :
<?php public function testAddMonth() { /* pass */ $date = new Zend_Date('2010-08-20T00:00:00+01:00',Zend_Date::ISO_8601); $date->addMonth(3); $this->assertEquals('2010-11-20T00:00:00+01:00', $date->get(Zend_Date::ISO_8601)); /* pass */ $date = new Zend_Date('2010-08-20T00:00:00+02:00', Zend_Date::ISO_8601); $date->addMonth(2); $this->assertEquals('2010-10-20T00:00:00+02:00', $date->get(Zend_Date::ISO_8601)); /* pass */ $date = new Zend_Date('2010-08-20T04:00:00+02:00', Zend_Date::ISO_8601); $date->addMonth(3); $this->assertEquals('2010-11-20T04:00:00+02:00', $date->get(Zend_Date::ISO_8601)); /* fail */ $date = new Zend_Date('2010-08-20T00:00:00+02:00', Zend_Date::ISO_8601); $date->addMonth(3); $this->assertEquals('2010-11-20T00:00:00+02:00', $date->get(Zend_Date::ISO_8601)); } ?>
Comments
Posted by matthias frey (mathf) on 2010-08-30T02:37:39.000+0000
test case :
<?php public function testAddMonth() { // pass $date = new Zend_Date('2010-08-20T00:00:00+01:00',Zend_Date::ISO_8601); $date->addMonth(3); $this->assertEquals('2010-11-20T00:00:00+01:00', $date->get(Zend_Date::ISO_8601)); // pass $date = new Zend_Date('2010-08-20T00:00:00+02:00', Zend_Date::ISO_8601); $date->addMonth(2); $this->assertEquals('2010-10-20T00:00:00+02:00',$date->get(Zend_Date::ISO_8601)); // pass $date = new Zend_Date('2010-08-20T04:00:00+02:00', Zend_Date::ISO_8601); $date->addMonth(3); $this->assertEquals('2010-11-20T04:00:00+02:00',$date->get(Zend_Date::ISO_8601)); // fail $date = new Zend_Date('2010-08-20T00:00:00+02:00', Zend_Date::ISO_8601); $date->addMonth(3); $this->assertEquals('2010-11-20T00:00:00+02:00',$date->get(Zend_Date::ISO_8601)); } ?>Posted by matthias frey (mathf) on 2010-08-30T02:38:36.000+0000
added a test case to illustrate the bug
Posted by matthias frey (mathf) on 2010-11-09T10:49:57.000+0000
any ideas/progress ? workarounds ? this is quite a show-stopper for me .. regards
Posted by matthias frey (mathf) on 2010-11-10T02:27:07.000+0000
It seems that setting "extend_month=true" in the Zend_Date options is a workaround
Posted by Mason Malone (masonm) on 2012-09-12T14:27:43.000+0000
Confirmed in ZF 1.12. Reproduction script: <? require('Zend/Date.php'); $a = new Zend_Date('2012-01-01T00:00:00+01:00'); $a->addMonth(3); var_dump($a->getIso()); ?>
Output: string(25) "2012-05-01T00:00:00+01:00"
Posted by Frank Brückner (frosch) on 2012-09-12T14:39:23.000+0000
Hi Mason, can you write a patch and unit tests for this issue? The component maintainer Thomas no longer works for the ZF project.
Posted by Mason Malone (masonm) on 2012-09-12T14:41:01.000+0000
Okay, I'll give it a shot