Issues

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

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)); } ?>

added a test case to illustrate the bug

any ideas/progress ? workarounds ? this is quite a show-stopper for me .. regards

It seems that setting "extend_month=true" in the Zend_Date options is a workaround

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"

Hi Mason, can you write a patch and unit tests for this issue? The component maintainer Thomas no longer works for the ZF project.

Okay, I'll give it a shot