Issues

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

Description

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


$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?


*** 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;

Comments

Fixed with r16350