Issues

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

Issue Type: Bug Created: 2012-02-22T16:10:11.000+0000 Last Updated: 2012-02-24T17:29:48.000+0000 Status: Open Fix version(s): Reporter: Sebastian Gro├če (sebastian.grosse) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

  • zend_date
  • zf-crteam-review

Related issues: Attachments:

Description

<pre class="highlight">
<?php
$date = new Zend_Date('2011-02-01 00:00:00');
echo $date->getIso(); //2011-02-01T00:00:00+01:00
echo '<br></br>';
echo $date->get(Zend_Date::DAY_OF_YEAR); //31

echo '';

$date->setDayOfYear(31);
echo $date->getIso(); //2011-01-31T00:00:00+01:00
echo '<br></br>';
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 '<br></br>';
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

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T17:29:33.000+0000

Confirmed. Test:

<pre class="highlight">
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:

<pre class="highlight">
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)

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts