ZF-12510: Swaped values when using Zend_Date::get() with Zend_Date::YEAR or Zend_Date::YEAR_SHORT

Issue Type: Bug Created: 2013-01-18T11:06:59.000+0000 Last Updated: 2013-04-05T16:07:02.000+0000 Status: Closed Fix version(s): Reporter: Mário Pereira (mariopereira) Assignee: None Tags: - Zend_Date

  • zend_date

Related issues: Attachments:


When trying to retrieve the year part of a Zend_Date, the constants Zend_Date::YEAR and Zend_Date::YEAR_SHORT return each others value.

Code sample:

$today = new Zend_Date(); // assume it is 2013-01-18 11:00:00 $year = $today->get(Zend_Date::YEAR); // $year should be "2013", it is "13" $shortYear = $today->get(Zend_Date::YEAR_SHORT); // $yearShort should be "13", it is "2013"


Posted by Frank Brückner (frosch) on 2013-01-18T13:12:56.000+0000

Hi Mário, I can not reproduce your problem. All unit tests are okay.

Here is a test for your example:

<pre class="highlight">
public function testDateShouldMatchLongAndShortYear()
    $date = new Zend_Date('31.12.2007');

    $this->assertEquals('2007', $date->get(Zend_Date::YEAR));
    $this->assertEquals('07', $date->get(Zend_Date::YEAR_SHORT));

Result: OK

Posted by Mário Pereira (mariopereira) on 2013-01-18T14:09:28.000+0000

You are right, there was a piece of information missing that I overlooked.

This behaviour only occurs when you set the 'format' option of Zend_Date to 'php'. I was setting it in the bootstrap and overlooked it in the test code I supplied.

I created an empty project just to test this and found the following: if I use Zend_Date::setOptions(array('format_type' => 'php')), then I get the results I said above. If I do not set that Zend_Date option, then the calls to get work as expected.

<pre class="highlight">
// no call to Zend_Date::setOptions();
$today = new Zend_Date();
$year = $today->get(Zend_Date::YEAR); // returns full 4 digit year
$shortYear = $today->get(Zend_Date::YEAR_SHORT); // returns 2 digit year


<pre class="highlight">
Zend_Date::setOptions(array('format_type' => 'php'));
$today = new Zend_Date();
$year = $today->get(Zend_Date::YEAR); // returns 2 digit year
$shortYear = $today->get(Zend_Date::YEAR_SHORT); // returns full 4 digit year

Is this an expected behaviour? I've been browsing the documentation and it does not say anything about Zend_Date::get() behaviour changing with or without this option.

Posted by Ralph Schindler (ralph) on 2013-04-05T16:07:02.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit:

Have you found an issue?

See the Overview section for more details.


© 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.