ZF-4537: Zend_Date returning wrong current date!

Description

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.

Comments

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:


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.

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

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

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.

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.

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.

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