Issues

ZF-9891: Zend_Date::equals() issues when 2 objects have different TZs

Issue Type: Bug Created: 2010-05-26T11:03:05.000+0000 Last Updated: 2010-05-30T03:15:15.000+0000 Status: Resolved Fix version(s): - 1.10.6 (22/Jun/10)

Reporter: Matthew Weier O'Phinney (matthew) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: Attachments:

Description

In debugging an issue in Zend_Feed, I came across an odd issue in Zend_Date, summarized in the code below:

<pre class="highlight">
$ts = strtotime('Sat, 07 Mar 2009 08:03:50 +0000');
$date1 = new Zend_Date($ts);
echo "Via strtotime: ", $date1->get(Zend_Date::RFC_2822), "\n";

$date2 = new Zend_Date();
$date2->set('Sat, 07 Mar 2009 08:03:50 +0000', Zend_Date::RFC_2822);
echo "Via direct set: ", $date2->get(Zend_Date::RFC_2822), "\n";

echo "Date 1 equals Date 2? " . ($date2->equals($date1) ? 'yes' : 'no') . "\n";

This returns the following:

<pre class="highlight">
Via strtotime: Sat, 07 Mar 2009 03:03:50 -0500
Via direct set: Sat, 07 Mar 2009 08:03:50 +0000
Date 1 equals Date 2? no

(TZ information will differ based on your current date.timezone settings)

The important thing to note is that the two dates are, in fact, the same -- they simply display different timezones. However, Zend_Date::equals() evaluates them as unequal.

Using DateTime and a similar approach:

<pre class="highlight">
$ts = strtotime('Sat, 07 Mar 2009 08:03:50 +0000');
$date1 = new DateTime('@' . $ts);
echo "DateTime via strtotime: ", $date1->format('r'), "\n";

$date2 = new DateTime('Sat, 07 Mar 2009 08:03:50 +0000');
echo "DateTime via string: ", $date2->format('r'), "\n";

echo "Date 1 equals Date 2? " . (($date1 == $date2) ? 'yes' : 'no') . "\n";

I get the expected result -- these are equal dates. Interestingly, the TZ information is kept separate, and the dates as echoed match; if I set the timezone separately, it will then reflect that in the output, but the dates still will be equal.

summary: equals() should be looking at timestamps when evaluating.

Comments

Posted by Thomas Weidner (thomas) on 2010-05-30T03:15:13.000+0000

Fixed with r22321

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