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

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');
2012-05-01T01:50:00-02:30
php> echo convertDate('2012-Jun-01 23:26');
2012-06-01T23:26:00-02:30
php> echo convertDate('2012-Jan-04 02:59');
2012-01-04T02:59:00-03:30

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