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
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
but
<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: https://github.com/zendframework/zf1/issues/50