Issues

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:

Description

Howdy:

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"> 
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:

<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

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:

<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');
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

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.

Copyright

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

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

Contacts