Zend_Date setTimezone() missing validation for timezone identifiers
0 reputation · 04 Feb 2020, 14:55 UTC
When working with Zend_Date in Zend Framework 1.x, developers often need to convert dates to different regional time zones using the setTimezone() method. The method currently accepts any string as a timezone identifier without verifying that it corresponds to a known zone; if the identifier is invalid, the object silently treats the date as UTC.
This behavior creates uncertainty because applications may inadvertently store or display incorrect times without any indication of failure, especially when timezone data is supplied from user input or configuration files. Determining whether the method should validate the identifier and raise an exception, log a warning, or continue with a fallback is an open design decision.
- Should
setTimezone()throw an exception when supplied with an unrecognized timezone identifier? - If validation is added, what type of exception (e.g., InvalidArgumentException) would be most appropriate?
- Alternatively, should the method emit a warning or notice while defaulting to UTC to maintain backward compatibility?