Horde_Date::add PHP Method

add() public method

Adds a number of seconds or units to this date, returning a new Date object.
public add ( $factor )
    public function add($factor)
    {
        $d = clone $this;
        if (is_array($factor) || is_object($factor)) {
            foreach ($factor as $property => $value) {
                $d->{$property} += $value;
            }
        } else {
            $d->sec += $factor;
        }
        return $d;
    }

Usage Example

Ejemplo n.º 1
0
Archivo: Time.php Proyecto: horde/horde
 /**
  * Return the next past or future Span for the time that this Repeater represents
  *   pointer - Symbol representing which temporal direction to fetch the next day
  *             must be either :past or :future
  */
 public function next($pointer = 'future')
 {
     parent::next($pointer);
     $halfDay = 3600 * 12;
     $fullDay = 3600 * 24;
     $first = false;
     if (!$this->currentTime) {
         $first = true;
         $midnight = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day));
         $yesterdayMidnight = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day - 1));
         $tomorrowMidnight = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day + 1));
         if ($pointer == 'future') {
             if ($this->ambiguous) {
                 foreach (array($midnight->add($this->type), $midnight->add($halfDay + $this->type), $tomorrowMidnight->add($this->type)) as $t) {
                     if ($t->compareDateTime($this->now) >= 0) {
                         $this->currentTime = $t;
                         break;
                     }
                 }
             } else {
                 foreach (array($midnight->add($this->type), $tomorrowMidnight->add($this->type)) as $t) {
                     if ($t->compareDateTime($this->now) >= 0) {
                         $this->currentTime = $t;
                         break;
                     }
                 }
             }
         } elseif ($pointer == 'past') {
             if ($this->ambiguous) {
                 foreach (array($midnight->add($halfDay + $this->type), $midnight->add($this->type), $yesterdayMidnight->add($this->type * 2)) as $t) {
                     if ($t->compareDateTime($this->now) <= 0) {
                         $this->currentTime = $t;
                         break;
                     }
                 }
             } else {
                 foreach (array($midnight->add($this->type), $yesterdayMidnight->add($this->type)) as $t) {
                     if ($t->compareDateTime($this->now) <= 0) {
                         $this->currentTime = $t;
                         break;
                     }
                 }
             }
         }
         if (!$this->currentTime) {
             throw new Horde_Date_Repeater_Exception('Current time cannot be null at this point');
         }
     }
     if (!$first) {
         $increment = $this->ambiguous ? $halfDay : $fullDay;
         $this->currentTime->sec += $pointer == 'future' ? $increment : -$increment;
     }
     return new Horde_Date_Span($this->currentTime, $this->currentTime->add(1));
 }
All Usage Examples Of Horde_Date::add