Issues

ZF-4867: getTimezoneFromString() uses wrong regular expression

Issue Type: Bug Created: 2008-11-07T13:21:34.000+0000 Last Updated: 2008-11-13T14:10:18.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Christian Welzel (gawain) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: Attachments:

Description

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

Results:

~$ 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 ( )

Comments

Posted by Thomas Weidner (thomas) on 2008-11-07T14:03:21.000+0000

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

Posted by Thomas Weidner (thomas) on 2008-11-07T14:19:53.000+0000

Fixed with r12391

Posted by Christian Welzel (gawain) on 2008-11-07T14:20:30.000+0000

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.

Posted by Christian Welzel (gawain) on 2008-11-07T14:34:36.000+0000

Thanks for fixing this!

Posted by Wil Sinclair (wil) on 2008-11-13T14:10:18.000+0000

Changing issues in preparation for the 1.7.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts