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

Issue Type: Bug Created: 2012-01-31T01:23:40.000+0000 Last Updated: 2012-02-24T00:25:45.000+0000 Status: Resolved Fix version(s): Reporter: Greg Gomez (ultra_blue) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Date

Related issues: Attachments:



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

<pre class="literal"> 

function convertDate($date) {
    $zDate = new Zend_Date();
    return $zDate->get(Zend_Date::W3C);

echo convertDate('2012-May-01 01:50');

Here's the output:

<pre class="literal">
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:

<pre class="literal">
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


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:

<pre class="highlight">
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:

<pre class="highlight">
php> echo convertDate('2012-May-01 01:50');
php> echo convertDate('2012-Jun-01 23:26');
php> echo convertDate('2012-Jan-04 02:59');

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.