Zend Framework

Zend_Date::setMonth adds +1 Year when using abbreviated month name

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.8.4
  • Fix Version/s: 1.9.0
  • Component/s: Zend_Date
  • Labels:
    None

Description

Using shortnames for methods of Zend_Date which proxy the _month() method add +1 year.

example
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
$d0 = new Zend_Date();
$d1 = new Zend_Date();

$d0->setYear(2000);
$d1->setYear(2000);

$d0->setMonth('January');
$d1->setMonth('Jan');

Zend_Debug::dump($d0->get(Zend_Date::YEAR));
Zend_Debug::dump($d1->get(Zend_Date::YEAR));

/**
* Output : 
* string(4) "2000"
* string(4) "2001"
*/

I believe this to be due to the code in Zend/Date.php around line 3343 - 3355.
It appears that arrays $monthlist and $monthlist2 are created, one containing full names, and then one containing abbreviated names.
They are then merged together, and looped through to find a match.
When a match is found $key + 1 is returned.

0-11 contain long names, January - December.
12-23 contain short names, Jan-Dec

So it seems that using short names results in a month number greater than 12, adding a year.
I cannot determine if this was intentional, as code following the referenced block seems confusing to me,
and much of Zend_Date is quite dense.
This may perhaps be some function of localization that I am not recognizing?

patch
*** Date.php	2009-06-28 20:18:29.000000000 -0400
--- Date.Fix.php	2009-06-28 20:18:48.000000000 -0400
***************
*** 3346,3351 ****
--- 3346,3354 ----
                  foreach ($monthlist as $key => $value) {
                      if (strtoupper($value) == strtoupper($month)) {
                          $found = $key + 1;
+ 						while($found > 12){
+ 							$found = $found - 12;
+ 						}
                          break;
                      }
                      ++$cnt;

Activity

Hide
Thomas Weidner added a comment -

Fixed with r16350

Show
Thomas Weidner added a comment - Fixed with r16350

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: