Pārlūkot izejas kodu

[ZF-9891] Zend_Date:

- changed behaviour on comparison
  the timezone is no longer taken into account
  when you want to compare the date object you now need to give the $part option

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22320 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 15 gadi atpakaļ
vecāks
revīzija
11053fa2cb
2 mainītis faili ar 14 papildinājumiem un 2 dzēšanām
  1. 2 2
      library/Zend/Date.php
  2. 12 0
      tests/Zend/DateTest.php

+ 2 - 2
library/Zend/Date.php

@@ -1136,7 +1136,7 @@ class Zend_Date extends Zend_Date_DateObject
      * @return integer  0 = equal, 1 = later, -1 = earlier
      * @throws Zend_Date_Exception
      */
-    public function compare($date, $part = null, $locale = null)
+    public function compare($date, $part = self::TIMESTAMP, $locale = null)
     {
         if (self::$_options['format_type'] == 'php') {
             $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
@@ -2679,7 +2679,7 @@ class Zend_Date extends Zend_Date_DateObject
      * @return boolean
      * @throws Zend_Date_Exception
      */
-    public function equals($date, $part = null, $locale = null)
+    public function equals($date, $part = self::TIMESTAMP, $locale = null)
     {
         $result = $this->compare($date, $part, $locale);
 

+ 12 - 0
tests/Zend/DateTest.php

@@ -5653,6 +5653,18 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $result = $date2->toArray();
         $this->assertEquals(1970, $result['year']);
     }
+
+    /**
+     * @ZF-9891
+     */
+    public function testComparingDatesWithoutOption()
+    {
+        $date  = new Zend_Date(strtotime('Sat, 07 Mar 2009 08:03:50 +0000'));
+        $date2 = new Zend_Date();
+        $date2->set('Sat, 07 Mar 2009 08:03:50 +0000', Zend_Date::RFC_2822);
+
+        $this->assertTrue($date2->equals($date));
+    }
 }
 
 class Zend_Date_TestHelper extends Zend_Date