ZF-2071: Zend_Date Constructor should respect timezone offsets in ISO 8601 date strings
Currently the Zend_Date constructor ignores timezone offsets specified in ISO 8601 date strings. For example:
date_default_timezone_set('America/Chicago'); $stringInDefaultTimezone = '2007-10-15T10:32:00-05:00'; $stringInCustomTimezone = '2007-10-15T10:32:00+09:00'; $dateInDefaultTimezone = new Zend_Date($stringInDefaultTimezone, Zend_Date::ISO_8601); $dateInCustomTimezone = new Zend_Date($stringInCustomTimezone, Zend_Date::ISO_8601); echo $dateInDefaultTimezone->get(Zend_Date::TIMESTAMP) . PHP_EOL; echo $dateInCustomTimezone->get(Zend_Date::TIMESTAMP) . PHP_EOL;
The above code, given Zend_Date 1.0.2, produces identical timestamps for both date objects, even though the original strings referred to two different moments in time. The only way to produce the correct timestamps given the current functionality of Zend_Date is to set the timezone offset prior to setting the rest of the date, like so:
$dateInCustomTimezone = new Zend_Date(); $dateInCustomTimezone->set('+09:00', Zend_Date::GMT_DIFF_SEP); $dateInCustomTimezone->set($stringInCustomTimezone, Zend_Date::ISO_8601);
This is much less convenient to the developer than simply specifying the date string in the constructor, and becomes particularly difficult when the developer is trying to process a dynamic collection of ISO 8601 dates in a variety of valid formats from a variety of timezones. Without knowing the timezone offset in advance, the developer will have to extract it from the string using regular expressions, which is an extra complexity many developers could do without.
It would be much more convenient to the developer if the constructor simply respected the timezone offset provided in the date string itself. Beyond that, it would be much more intuitive, as developers specifying timezone offsets in their date strings are probably expecting it to "just work"; I know that was my experience :)
Thanks for reading!