Issues

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

Description

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"

Comments

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

Here is a test for your example:


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

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.


// 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

but


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.

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf1/issues/50