Ver Fonte

[GENERIC] Zend_Date:

- fixed some methods not providing fluid interface

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19530 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas há 16 anos atrás
pai
commit
7114873435
2 ficheiros alterados com 34 adições e 28 exclusões
  1. 18 12
      library/Zend/Date.php
  2. 16 16
      tests/Zend/DateTest.php

+ 18 - 12
library/Zend/Date.php

@@ -240,6 +240,7 @@ class Zend_Date extends Zend_Date_DateObject
         if (empty($options)) {
             return self::$_options;
         }
+
         foreach ($options as $name => $value) {
             $name  = strtolower($name);
 
@@ -1049,7 +1050,7 @@ class Zend_Date extends Zend_Date_DateObject
      * @param  string|integer|array|Zend_Date  $date    Date or datepart to set
      * @param  string                          $part    OPTIONAL Part of the date to set, if null the timestamp is set
      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
-     * @return integer|string  new datepart
+     * @return Zend_Date Provides fluid interface
      * @throws Zend_Date_Exception
      */
     public function set($date, $part = null, $locale = null)
@@ -1061,8 +1062,8 @@ class Zend_Date extends Zend_Date_DateObject
         $zone = $this->getTimezoneFromString($date);
         $this->setTimezone($zone);
 
-        $result = $this->_calculate('set', $date, $part, $locale);
-        return $result;
+        $this->_calculate('set', $date, $part, $locale);
+        return $this;
     }
 
     /**
@@ -1087,7 +1088,7 @@ class Zend_Date extends Zend_Date_DateObject
         }
 
         $this->_calculate('add', $date, $part, $locale);
-        return $this->toString($part, 'iso', $locale);
+        return $this;
     }
 
     /**
@@ -1110,7 +1111,7 @@ class Zend_Date extends Zend_Date_DateObject
         }
 
         $this->_calculate('sub', $date, $part, $locale);
-        return $this->toString($part, 'iso', $locale);
+        return $this;
     }
 
     /**
@@ -2640,6 +2641,7 @@ class Zend_Date extends Zend_Date_DateObject
         if ($result == 0) {
             return true;
         }
+
         return false;
     }
 
@@ -2661,6 +2663,7 @@ class Zend_Date extends Zend_Date_DateObject
         if ($result == -1) {
             return true;
         }
+
         return false;
     }
 
@@ -2683,6 +2686,7 @@ class Zend_Date extends Zend_Date_DateObject
         if ($result == 1) {
             return true;
         }
+
         return false;
     }
 
@@ -4296,7 +4300,7 @@ class Zend_Date extends Zend_Date_DateObject
      *
      * @param  integer $precision Precision for the fractional datepart 3 = milliseconds
      * @throws Zend_Date_Exception
-     * @return void
+     * @return Zend_Date Provides fluid interface
      */
     public function setFractionalPrecision($precision)
     {
@@ -4305,6 +4309,7 @@ class Zend_Date extends Zend_Date_DateObject
             throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", $precision);
         }
         $this->_precision = (int) $precision;
+        return $this;
     }
 
 
@@ -4325,7 +4330,7 @@ class Zend_Date extends Zend_Date_DateObject
      *
      * @param  integer|Zend_Date $milli     (Optional) Millisecond to set, when null the actual millisecond is set
      * @param  integer           $precision (Optional) Fraction precision of the given milliseconds
-     * @return integer|string
+     * @return Zend_Date Prodives fluid interface
      */
     public function setMilliSecond($milli = null, $precision = null)
     {
@@ -4347,7 +4352,7 @@ class Zend_Date extends Zend_Date_DateObject
 
         $this->_fractional = 0;
         $this->addMilliSecond($milli, $precision);
-        return $this->_fractional;
+        return $this;
     }
 
 
@@ -4356,7 +4361,7 @@ class Zend_Date extends Zend_Date_DateObject
      *
      * @param  integer|Zend_Date $milli     (Optional) Millisecond to add, when null the actual millisecond is added
      * @param  integer           $precision (Optional) Fractional precision for the given milliseconds
-     * @return integer|string
+     * @return Zend_Date Provides fluid interface
      */
     public function addMilliSecond($milli = null, $precision = null)
     {
@@ -4404,7 +4409,7 @@ class Zend_Date extends Zend_Date_DateObject
             }
         }
 
-        return $this->_fractional;
+        return $this;
     }
 
 
@@ -4413,11 +4418,12 @@ class Zend_Date extends Zend_Date_DateObject
      *
      * @param  integer|Zend_Date $milli     (Optional) Millisecond to sub, when null the actual millisecond is subtracted
      * @param  integer           $precision (Optional) Fractional precision for the given milliseconds
-     * @return integer
+     * @return Zend_Date Provides fluid interface
      */
     public function subMilliSecond($milli = null, $precision = null)
     {
-        return $this->addMilliSecond(0 - $milli, $precision);
+        $this->addMilliSecond(0 - $milli, $precision);
+        return $this;
     }
 
     /**

+ 16 - 16
tests/Zend/DateTest.php

@@ -869,9 +869,9 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2->setTimezone(date_default_timezone_get());
 
         $retour = $date->set(1234567890);
-        $this->assertSame('1234567890', (string)$retour               );
-        $this->assertSame('1010101010', (string)$date->set($d2       ));
-        $this->assertSame('1234567891', (string)$date->set(1234567891));
+        $this->assertSame('1234567890', $retour->getTimestamp());
+        $this->assertSame('1010101010', $date->set($d2)->getTimestamp());
+        $this->assertSame('1234567891', $date->set(1234567891)->getTimestamp());
 
         try {
             $date->set('noday', Zend_Date::DAY);
@@ -2407,10 +2407,10 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2   = new Zend_Date(1010101010,null,$locale);
 
         $retour = $date->set(1234567890);
-        $this->assertSame((string)$retour,'1234567890');
-        $this->assertSame((string)$date->add(10),'1234567900');
-        $this->assertSame((string)$date->add(-10),'1234567890');
-        $this->assertSame((string)$date->add(0),'1234567890');
+        $this->assertSame($retour->getTimestamp(),'1234567890');
+        $this->assertSame($date->add(10)->getTimestamp(),'1234567900');
+        $this->assertSame($date->add(-10)->getTimestamp(),'1234567890');
+        $this->assertSame($date->add(0)->getTimestamp(),'1234567890');
 
         $date->set($d2);
         $date->add(10, Zend_Date::DAY);
@@ -2803,10 +2803,10 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2   = new Zend_Date(1010101010,null,$locale);
 
         $retour = $date->set(1234567890);
-        $this->assertSame('1234567890', (string)$retour        );
-        $this->assertSame('1234567900', (string)$date->sub(-10));
-        $this->assertSame('1234567890', (string)$date->sub( 10));
-        $this->assertSame('1234567890', (string)$date->sub(  0));
+        $this->assertSame('1234567890', $retour->getTimestamp());
+        $this->assertSame('1234567900', $date->sub(-10)->getTimestamp());
+        $this->assertSame('1234567890', $date->sub( 10)->getTimestamp());
+        $this->assertSame('1234567890', $date->sub(  0)->getTimestamp());
 
         $date->set($d2);
         $date->sub(-10, Zend_Date::DAY);
@@ -3201,7 +3201,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2   = new Zend_Date(1010101010,null,$locale);//03.01.2002 15:36:50
 
         $retour = $date->set(1234567890); //13.02.2009 15:31:30
-        $this->assertSame('1234567890', (string)$retour);
+        $this->assertSame('1234567890', $retour->getTimestamp());
         $this->assertSame( 0, $date->compare(1234567890));
         $this->assertSame( 1, $date->compare(1234567800));
         $this->assertSame(-1, $date->compare(1234567899));
@@ -3247,7 +3247,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2   = new Zend_Date(1010101010,null,$locale);
 
         $retour = $date->set(1234567890);
-        $this->assertSame('1234567890', (string)$retour);
+        $this->assertSame('1234567890', $retour->getTimestamp());
         $this->assertTrue( $date->equals(1234567890));
         $this->assertFalse($date->equals(1234567800));
 
@@ -3266,7 +3266,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2   = new Zend_Date(1010101010,null,$locale);
 
         $retour = $date->set(1234567890);
-        $this->assertSame('1234567890', (string)$retour);
+        $this->assertSame('1234567890', $retour->getTimestamp());
         $this->assertFalse($date->isEarlier(1234567890));
         $this->assertFalse($date->isEarlier(1234567800));
         $this->assertTrue( $date->isEarlier(1234567899));
@@ -3287,7 +3287,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         $d2   = new Zend_Date(1010101010,null,$locale);
 
         $retour = $date->set(1234567890);
-        $this->assertSame('1234567890', (string)$retour);
+        $this->assertSame('1234567890', $retour->getTimestamp());
         $this->assertFalse($date->isLater(1234567890));
         $this->assertTrue( $date->isLater(1234567800));
         $this->assertFalse($date->isLater(1234567899));
@@ -4471,7 +4471,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
             $this->assertSame("$weekday.01.1970 00:00:00", $dw->toString());
         }
     }
-    
+
     /**
      * @group   ZF-8332
      */