Returns a copy of this Duration with the specified duration added.

@param \Brick\DateTime\Duration $duration

@return \Brick\DateTime\Duration
427714
public function plus(Duration $duration) : Duration
    {
        if ($duration->isZero()) {
            return $this;
        }

        $seconds = $this->seconds + $duration->seconds;
        $nanos = $this->nanos + $duration->nanos;

        if ($nanos >= LocalTime::NANOS_PER_SECOND) {
            $nanos -= LocalTime::NANOS_PER_SECOND;
            $seconds++;
        }

        return new Duration($seconds, $nanos);
    }
597679
public function cache($result, $key, $duration = null)
    {
        if ($key && $this->getCache()) {
            $this->getCache()->set($key, $result, $duration);
        }
        return $result;
    }
400930
public function Add( $duration )
	{
		if ( ! $duration instanceof DurationValue )
		{
			throw new \InvalidArgumentException();
		}

		$totalMonths = $this->getTotalMonths() + $duration->getTotalMonths();
		$invert = 0 > $totalMonths;
		$totalMonths = abs( $totalMonths );
		$years = intval( $totalMonths / 12 );
		$months = $totalMonths % 12;

		$di = new \DateInterval( sprintf( "P%02sY%02sM", $years, $months ) );
		$di->hasValue = $di->y || $di->m;
		$di->invert = $invert;
		$di->microseconds = 0;

		$this->Value = $di;
		// $this->type = $this->Value->hasValue
		// 	? XPATH20_DURATION_TYPE_ANY
		// 	: XPATH20_DURATION_TYPE_YEARMONTH;
	}
1089327
public static String fromDuration(Duration duration) {
		if (duration == null) {
			return null;
		}
		return humanize(duration.get(ChronoUnit.MILLIS));
	}
1316966
public function expiresAfter($time)
    {
        if ($time instanceof \DateInterval) {
            $time = (int) $time->format("%r%s");
        }

        $this->expiration = time() + $time;

        return $this;
    }
449713
public function plusDuration(Duration $duration) : ZonedDateTime
    {
        return ZonedDateTime::ofInstant($this->instant->plus($duration), $this->timeZone);
    }
1204262
function _format_duration( $duration ) {
    if( !isset( $duration['week'] ) &&
        !isset( $duration['day'] )  &&
        !isset( $duration['hour'] ) &&
        !isset( $duration['min'] )  &&
        !isset( $duration['sec'] ))
      return;
    $output = 'P';
    if( isset( $duration['week'] ) && ( 0 < $duration['week'] ))
      $output       .= $duration['week'].'W';
    else {
      if( isset($duration['day'] ) && ( 0 < $duration['day'] ))
        $output     .= $duration['day'].'D';
      if(( isset( $duration['hour']) && ( 0 < $duration['hour'] )) ||
         ( isset( $duration['min'])  && ( 0 < $duration['min'] ))  ||
         ( isset( $duration['sec'])  && ( 0 < $duration['sec'] ))) {
        $output     .= 'T';
        if( 0 < $duration['hour'] ) {
          $output   .= $duration['hour'].'H';
          if( 0 < $duration['min'] ) {
            $output .= $duration['min'].'M';
            if( 0 < $duration['sec'] )
              $output .= $duration['sec'].'S';
          }
          elseif( 0 < $duration['sec'] )
            $output .= '0M'.$duration['sec'].'S';
        }
        elseif( 0 < $duration['min'] ) {
          $output   .= '0H'.$duration['min'].'M';
          if( 0 < $duration['sec'] )
            $output .= $duration['sec'].'S';
        }
        elseif( 0 < $duration['sec'] )
          $output   .= '0H0M'.$duration['sec'].'S';
      }
    }
    return $output;
  }
600748
public static function formatDuration($duration, $precision = 3)
    {
        if ($duration < 1) {
            $duration *= 1000;
            $unit = 'ms';
        } else {
            $unit = 's ';
        }

        return self::toPrecision($duration, $precision) . $unit;
    }
544904
public final function expiresAfter($time)
   {
       $this->timeToLive = $time instanceof DateInterval
                         ? (new DateTime())->add($time)->getTimestamp()
                         - time()
                         : (int) $time;
       return $this;
   }
517703
public static function createFromEndAndDuration(DateTimeOfDay $end, Duration $duration)
    {
        return static::create($end->sub($duration), $end);
    }
311592
public function getTemporaryCredential($durationInSeconds = 43200)
    {
        $now      = time();
        $expireAt = $now + $durationInSeconds;
        $cmd      = $this->getCommand(
            "GetSessionToken",
            [
                "DurationSeconds" => $durationInSeconds,
            ]
        );
        $result   = $this->execute($cmd);
        
        $credential                  = new TemporaryCredential();
        $credential->expireAt        = $expireAt;
        $credential->sessionToken    = $result['Credentials']['SessionToken'];
        $credential->accessKeyId     = $result['Credentials']['AccessKeyId'];
        $credential->secretAccessKey = $result['Credentials']['SecretAccessKey'];
        $credential->expireDateTime  = $result['Credentials']['Expiration'];
        
        return $credential;
    }
744772
public Duration subtract( Duration duration ) {
        return new Duration(this.durationInNanos - (duration == null ? 0l : duration.longValue()));
    }
798964
public function plusDuration(Duration $duration) : LocalTime
    {
        return $this
            ->plusSeconds($duration->getSeconds())
            ->plusNanos($duration->getNanos());
    }
1235623
public function setDuration($duration)
    {
        // get dom element
        $durationDomElement = $this->getDomElement()->getElementsByTagName('Duration')->item(0);
        if (!$durationDomElement) {
            $durationDomElement = $this->getDomElement()->ownerDocument->createElement('Duration');
            $this->getDomElement()->firstChild->appendChild($durationDomElement);
        }

        // set value
        if (is_numeric($duration)) {
            // in seconds
            $duration = $this->secondsToString($duration);
        }

        $durationDomElement->nodeValue = $duration;

        return $this;
    }
1319238
public function getDuration() : ?string 
    {
        if ( ! $this->hasDuration()) {
            $this->setDuration($this->getDefaultDuration());
        }
        return $this->duration;
    }
815614
public function period($time) {
		$Dates = array();
		$NextDate = $this->start();
		while ($NextDate <= $this->_endDate) {
			$Dates[] = clone $NextDate;
			$NextDate->modify("+$time");
		}
		return new ArrayIterator($Dates);
	}
390465
public static function createFromDateString($duration): self
    {
        $duration = parent::createFromDateString($duration);
        if (false === $duration) {
            return $duration;
        }

        $new = new self('PT0S');
        foreach ($duration as $name => $value) {
            $new->$name = $value;
        }

        return $new;
    }