ZF-4867: getTimezoneFromString() uses wrong regular expression


Zend_Date uses in its function getTimezoneFromString() the following code to find a timezone string ("CET" or "Europe/Berlin"):

reg_match('/(\w{3,30})/', $zone, $match);

Unfortunately this regexp does not match the second form of time zone. Its only matches the first part ("Europe" in the above example). And even more annoying: it also matches strings of this form: 2008-12-31 (result: "2008").

To correct this issue, the better regexp would be this:

reg_match('/([[:alpha:]\/]{3,30})/', $zone, $match);


~$ php -r "\$m=array(); preg_match('/([[:alpha:]\/]{3,30})/','Europe/Berlin', \$m); print_r(\$m);" Array ( [0] => Europe/Berlin [1] => Europe/Berlin ) ~$ php -r "\$m=array(); preg_match('/([[:alpha:]\/]{3,30})/','2008-12-31 12:00:00', \$m); print_r(\$m);" Array ( )


The mentioned line does only check if there is a character string. The proper timezone is checked and set within setTimeZone.

Fixed with r12391

Then please define, what you are refering to as "character string". If you mean "a string consisting only of letters" than this is the wrong regexp as "/(\w{3,30})/" also matches numbers. And if you mean "a string consisting a valid timezone like Europe/Berlin" its wrong too, because it will only extract "Europe".

Try this with Zend_Date: $date = new Zend_Date(); $date->set('2008-12-31 12:00:00', 'YYYY-MM-dd HH:mm:ss');

It will try to set "2008" as timezone which results in a php-warning. And this is because getTimezoneFromString() uses the wrong regexp to extract the timezone from the string.

Thanks for fixing this!

Changing issues in preparation for the 1.7.0 release.