ZF-12034: Zend Date switches month and day when certain times appear in the constructor's arguments



Sorry to be obtuse in the Summary -- I'm a little punch drunk from narrowing this one down. Here's the deal:


function convertDate($date) {
    $zDate = new Zend_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


Added some formatting to make it easier to read.

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:

function convertDate($date) {
    $zDate = new Zend_Date($date, 'yyyy-MMM-dd HH:mm');
    return $zDate->get(Zend_Date::W3C);

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:

php> echo convertDate('2012-May-01 01:50');
php> echo convertDate('2012-Jun-01 23:26');
php> echo convertDate('2012-Jan-04 02:59');

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