ZF-12034: Zend Date switches month and day when certain times appear in the constructor's arguments
Description
Howdy:
Sorry to be obtuse in the Summary -- I'm a little punch drunk from narrowing this one down. Here's the deal:
require_once('ZendFramework-1.11.11/library/Zend/Date.php');
function convertDate($date) {
$zDate = new Zend_Date();
$zDate->setTimezone('Etc/UTC');
$zDate->set($date);
return $zDate->get(Zend_Date::W3C);
}
echo convertDate('2012-May-01 01:50');
Here's the output:
This is true for any time between 01:50 and 01:59. 01:49 and 02:00 work as expected.
I get this for output:
Here's another example:
Output: ````
I can provide other examples, but you get the idea.
The format in get() doesn't seem to matter. I tried Zend_Date::W3C, Zend_Date::RSS and Zend_Date::DATE_FULL.
Thanks, Greg
Comments
Posted by Greg Gomez (ultra_blue) on 2012-01-31T01:30:33.000+0000
Added some formatting to make it easier to read.
Posted by Adam Lundrigan (adamlundrigan) on 2012-02-23T23:05:36.000+0000
Zend_Date::set does not understand passing that format of date as the first argument. It's primarily used to set components of dates, and if the second argument is omitted it assumes the first is a timestamp. To create a date object with the format you use in your example, you'll need to do this:
Of course, if you want the dates passed in to be UTC, you'll need to use {{date_default_timezone_set}} beforehand. Changing the timezone on the Zend_Db object will offset the time stored in that object from the server's local time to UTC.
When I run the above function (in my local timezone) using your examples I get this:
Posted by Greg Gomez (ultra_blue) on 2012-02-24T00:25:45.000+0000
Hi, Adam:
Thanks so much for your reply -- it's crystal clear now. And it's in the docs, as well -- I'm not sure why I thought I could get away with a date/time in an arbitrary format as I was attempting to do.
Thanks again! Greg