ZF-12141: Zend_Date::toString returns wrong date for some 'php' formats
Description
Simple example:
$date = new Zend_Date();
echo $date->toString(DateTime::ATOM, 'php'); // 2012-04-09\UTC12:21:48+00:00
This code display 2012-04-09\UTC12:21:48+00:00 but 2012-04-09T12:21:48+00:00 is expected instead.
But example bellow works as expected:
$date = new Zend_Date();
echo $date->toString(Zend_Date::ATOM); // 2012-04-09T12:21:48+00:00
The basic problem is that Zend_Date::toString uses Zend_Locale_Format::convertPhpToIsoFormat for php format type that works incorrectly with formats that contain symbols are escaped with backslash (\T in example). Zend_Locale_Format::convertPhpToIsoFormat just splits format string to array and convert each symbol to ISO separately. But it should be more complicated. The simplest way to fix it is to get escaped symbol right after backslash and put it into single quotes so Zend_Date will parse it as comment.
Comments
Posted by Vladyslav Mustafin (vladm) on 2012-04-09T16:19:03.000+0000
It might looks like below:
Posted by Vladyslav Mustafin (vladm) on 2012-04-09T16:21:41.000+0000
Wrong return in my example, it should be: ``` Sorry for typo.
Posted by Patrick Heck (patrickheck) on 2012-05-02T17:18:34.000+0000
Hi Mustafin,
thanks for the code snippet. However I found two issues that still exist: 1. Inserting of consecutive escaped characters like "\a\t" result in "a't" 2. A masked backslash was not displayed
My suggestion is to improve it like this:
Posted by Patrick Heck (patrickheck) on 2012-05-02T18:10:01.000+0000
I just realized that the string "\a\'\b" wouldn't work properly with this code. The result would be "a''b" instead of "a'b". To fix this the escaped sequence should only be terminated if the current character is != "'".
Posted by Vladyslav Mustafin (vladm) on 2012-08-09T08:55:34.000+0000
Hi Heck,
{quote} 2. A masked backslash was not displayed {quote} If you try to get an output of
You could check it with this codeSo masked backslash in php date format should be converted to a single backslash for iso date format. No needs to escape it in iso, but with your last snippet it will.
`
\ With small additional condition we can get the expected behaviour:
Posted by Vladyslav Mustafin (vladm) on 2012-08-11T08:08:38.000+0000
Yet another typo please use '$value' instead of '$v' in my examples. Sorry for that.