ZF-4537: Zend_Date returning wrong current date!

Issue Type: Bug Created: 2008-10-09T11:58:03.000+0000 Last Updated: 2010-01-02T02:19:01.000+0000 Status: Resolved Fix version(s): - 1.6.2 (13/Oct/08)

Reporter: jl (colonelforbin) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: Attachments:


Zend_Date is returning the wrong date when creating a new object with no parameters.

Example: $logDate = new Zend_Date($dateStr, "YYYY-MM-DD HH:mm"); $curDate = new Zend_Date(); echo "Log: $logDate\n"; echo "Cur: " . $curDate . "\n"; echo "Time: " . gmdate("Y-m-d\TH:i:s.000\Z", time()) . "\n";

I get the following output: Log: Oct 9, 2008 2:28:00 PM Cur: Dec 31, 1969 7:28:05 PM Time: 2008-10-09T18:56:05.000Z

So Zend_Date() is returning a 1969 date, while time() is returning the correct date. Zend_Date's documentation claims that it uses the time() function to get the correct date, so the issue must lie within Zend_Date. The wierd thing is that Zend_Date works for the first call, when it is assigned into $logDate, it is only after the second call when it is assigned into $curDate that it gives the incorrect date.


Posted by Thomas Weidner (thomas) on 2008-10-09T12:19:44.000+0000

It does... see line 184, 185, 3367

You are the only one who has such a problem since 2 years. So it must be eighter a php version problem or a environment problem.

So try the following:

<pre class="highlight">
print time();

$date = new Zend_Date();
print $date->getIso();
print $date->getTimestamp();

$date = Zend_Date::now();
print $date->getIso();

$date = Zend_Date(time());
print $date->getIso();

$date = Zend_Date(200000);
print $date->getIso();

$date = Zend_Date('20.March.2008', 'en');
print $date->getIso();

Additionally give your ZF version, your PHP version, your environment, your locale.

Posted by Thomas Weidner (thomas) on 2008-10-09T12:24:13.000+0000

I still need the data mentioned above to be able to seek where the problem could be.

Posted by jl (colonelforbin) on 2008-10-09T12:53:32.000+0000

Ok, after running: {quote} print time() . PHP_EOL;

$date = new Zend_Date(); print $date->getIso() . PHP_EOL; print $date->getTimestamp() . PHP_EOL;

$date = Zend_Date::now(); print $date->getIso() . PHP_EOL;

$date = new Zend_Date(time()); print $date->getIso() . PHP_EOL;

$date = new Zend_Date(200000); print $date->getIso() . PHP_EOL;

$date = new Zend_Date('20.March.2008', 'en'); print $date->getIso() . PHP_EOL; {quote}

I got: {quote} 1223581542 2008-10-09T15:45:42-04:00 1223581542 2008-10-09T15:45:42-04:00 2008-10-09T15:45:42-04:00 1970-01-03T02:33:20-05:00 2008-03-20T00:00:00-04:00 {quote}

So it seems that the issue only occurs in the original code I gave you, which probably doesn't help you much :(

Btw, i'm using ZF 1.53, php 5.2.6, intel/ubuntu-8.04, United States/New_York

Posted by Thomas Weidner (thomas) on 2008-10-09T13:07:05.000+0000

No it does not.

And also your assumption of the second call of Zend_Date is not correct. As you see we are calling it multiple times and all works as expected.

So running the testcode on your environment I don't think that the problem is origin of Zend_Date. If you have no further idea or testcode I will close this issue as we showed that the problem is not related to Zend_Date.

As workaround, if you still expect such problems, I would try to use the static now() method and see if it works.

Posted by jl (colonelforbin) on 2008-10-09T13:37:04.000+0000

Ok, thanks for looking into this, I guess I'm the only one seeing this issue so you should go ahead and close the issue.

Posted by Thomas Weidner (thomas) on 2008-10-09T14:21:36.000+0000

Issue not reproducable. Use static now, or give the timestamp as integer value at object creation.

Feel free to reopen this issue if you have new informations for reproduction.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-01-02T02:19:01.000+0000

In case you found this issue through google, hoping to find an explanation why Zend_Date returns the wrong year, please look here: ZF-5297

Have you found an issue?

See the Overview section for more details.


© 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.