ZF-12065: Zend_Date inconsistence using set/get with Zend_Date::DAY_OF_YEAR

Description


<?php
$date = new Zend_Date('2011-02-01 00:00:00');
echo $date->getIso(); //2011-02-01T00:00:00+01:00
echo '
'; echo $date->get(Zend_Date::DAY_OF_YEAR); //31 echo ''; $date->setDayOfYear(31); echo $date->getIso(); //2011-01-31T00:00:00+01:00 echo '
'; echo $date->get(Zend_Date::DAY_OF_YEAR); //30 echo ''; //same as setDayOfYear() $date->set(32, Zend_Date::DAY_OF_YEAR); echo $date->getIso(); //2011-01-31T00:00:00+01:00 echo '
'; echo $date->get(Zend_Date::DAY_OF_YEAR); //31

I think after setting a value you should get the same value when reading it.

Using set the days of a year start from 1, for get they start from 0.

Is that a bug or wanted?

Comments

Confirmed. Test:


Index: tests/Zend/DateTest.php
===================================================================
--- tests/Zend/DateTest.php     (revision 24628)
+++ tests/Zend/DateTest.php     (working copy)
@@ -5678,6 +5678,20 @@
         $date = new Zend_Date($t, 'yyyy-MM-dd HH:mm:ss');
         $this->assertEquals($t, $date->toString('yyyy-MM-dd HH:mm:ss'));
     }
+
+    /**
+     * @group ZF-12065
+     */
+    public function testDayOfYearManipulation()
+    {
+        date_default_timezone_set('Europe/Berlin');
+        $date = new Zend_Date('2009-02-13T14:53:27+01:00', Zend_Date::ISO_8601);
+        $this->assertEquals(43, $date->get(Zend_Date::DAY_OF_YEAR));
+
+        $date = new Zend_Date('2009-01-01T14:53:27+01:00', Zend_Date::ISO_8601);
+        $date->set(43, Zend_Date::DAY_OF_YEAR);
+        $this->assertEquals('2009-02-13T14:53:27+01:00', $date->getIso());
+    }

 }

Result:


1) Zend_DateTest::testDayOfYearManipulation
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-2009-02-13T14:53:27+01:00
+2009-02-12T14:53:27+01:00

tests/Zend/DateTest.php:5693 (last assert)