Change the period date interval.

@param DateInterval|string $interval

@throws \InvalidArgumentException

@return $this
199672
public function setDateInterval($interval)
    {
        if (!$interval = CarbonInterval::make($interval)) {
            throw new InvalidArgumentException('Invalid interval.');
        }

        if ($interval->spec() === 'PT0S') {
            throw new InvalidArgumentException('Empty interval is not accepted.');
        }

        $this->dateInterval = $interval;

        $this->isDefaultInterval = false;

        $this->handleChangedParameters();

        return $this;
    }
341735
public function withIntervalInMinutes($intervalInMinutes)
    {
        $this->validateInterval($intervalInMinutes);
        $this->interval = $intervalInMinutes;
        $this->intervalUnit = IntervalUnit::MINUTE;

        return $this;
    }
870406
public function applyDateInterval($interval, $unit)
    {
        if ($interval > 0) {
            $this->add(new RhubarbDateInterval("P{$interval}{$unit}"));
        } elseif ($interval < 0) {
            $interval *= -1;
            $this->sub(new RhubarbDateInterval("P{$interval}{$unit}"));
        }
    }
25562
public static function getSecondsFromInterval(DateInterval $interval)
    {
        $map   = [31536000, 2592000, 86400, 3600, 60, 1];
        $parts = explode('.', $interval->format('%y.%m.%d.%h.%i.%s'));
        $value = 0;

        foreach ($parts as $key => $val) {
            $value+= $val * $map[$key];
        }

        return $value;
    }
554575
public function Sub( $duration )
	{
		if ( ! $duration instanceof DurationValue )
		{
			throw new \InvalidArgumentException();
		}

		$duration->Value->invert = ! $duration->Value->invert;
		$this->Add( $duration );

		// // Finally convert $multipliedInterval into a normalized interval
		// /**
		//  * @var \DateTime $dt
		//  */
		// $dt = new \DateTimeImmutable( "2017-06-07" );
		// /**
		//  * @var \DateTime $added
		//  */
		// $added = $dt->add( $this->Value );
		// $duration->Value->invert = ! $duration->Value->invert;
		// /**
		//  * @var \DateTime $subtracted
		//  */
		// $subtracted = $added->add( $duration->Value );
		// /**
		//  * @var \DateInterval $diff
		//  */
		// $diff = $subtracted->diff( $dt );
		// $diff->invert = $diff->days == 0 ? false : ! $diff->invert;
        //
		// $this->Value = $diff;
	}
60374
protected function modifyFromInterval($interval, $invert = false)
	{
		if ($invert)
		{
			$this->sub($interval);
		}
		else
		{
			$this->add($interval);
		}

		return $this;
	}
619083
public function set(int $offset, Period $interval): void
    {
        $this->get($offset);
        $this->intervals[$offset] = $interval;
    }
5002
public static DateInterval from(ChronoInterval<PlainDate> interval) {

        if (interval instanceof DateInterval) {
            return DateInterval.class.cast(interval);
        } else {
            return new DateInterval(interval.getStart(), interval.getEnd());
        }

    }
746779
public static function modifyNow($interval, $format = self::DEFAULT_TIME_FORMAT)
    {
        return Clock::now()->toDateTime()->modify($interval)->format($format);
    }
811064
public function signalInterval(float $interval)
    {
        // @codeCoverageIgnoreStart
        if (null === $this->signalTimer) {
            throw new SignalHandlingDisabledError();
        } // @codeCoverageIgnoreEnd

        $this->signalTimer->stop();
        $this->signalTimer = $this->timer($interval, true, [$this->signalManager, 'tick']);
        $this->signalTimer->unreference();
    }
856913
public function toSpec(\DateInterval $interval = null)
    {
        if ((null === $interval) && isset($this)) {
            $interval = $this;
        }

        $string = 'P';

        foreach (self::$date as $property => $suffix) {
            if ($interval->{$property}) {
                $string .= $interval->{$property} . $suffix;
            }
        }

        if ($interval->h || $interval->i || $interval->s) {
            $string .= 'T';

            foreach (self::$time as $property => $suffix) {
                if ($interval->{$property}) {
                    $string .= $interval->{$property} . $suffix;
                }
            }
        }

        return $string;
    }
507713
public function withIntervalInWeeks($intervalInWeeks)
    {
        $this->validateInterval($intervalInWeeks);
        $this->interval = $intervalInWeeks;
        $this->intervalUnit = IntervalUnit::WEEK;

        return $this;
    }
1211444
public function add(DateInterval $interval)
    {
        $sign = $interval->invert === 1 ? -1 : 1;

        if (self::wasCreatedFromDiff($interval)) {
            $this->dayz = $this->dayz + $interval->days * $sign;
        } else {
            $this->years = $this->years + $interval->y * $sign;
            $this->months = $this->months + $interval->m * $sign;
            $this->dayz = $this->dayz + $interval->d * $sign;
            $this->hours = $this->hours + $interval->h * $sign;
            $this->minutes = $this->minutes + $interval->i * $sign;
            $this->seconds = $this->seconds + $interval->s * $sign;
        }

        return $this;
    }
731474
public function remove(int $offset): Period
    {
        $interval = $this->get($offset);
        unset($this->intervals[$offset]);

        $this->intervals = array_values($this->intervals);

        return $interval;
    }
562301
public function addInterval($number, $period)
  {
    $int = new \DateInterval(sprintf('P%d%s', abs($number), $period));

    if ($number > 0) {
      $this->add($int);
    } elseif ( $number < 0) {
      $this->sub($int);
    }

    return $this;
  }
492953
public function equals(DateInterval $interval)
	{
		$years   = $this->y == $interval->y;
		$months  = $this->m == $interval->m;
		$days    = $this->d == $interval->d;
		$hours   = $this->h == $interval->h;
		$minutes = $this->i == $interval->i;
		$seconds = $this->s == $interval->s;
		$invert  = $this->invert == $interval->invert;

		return $years && $months && $days && $hours && $minutes && $seconds && $invert;
	}
394328
public function withIntervalInSeconds($intervalInSeconds)
    {
        $this->validateInterval($intervalInSeconds);

        $this->interval = $intervalInSeconds;
        $this->intervalUnit = IntervalUnit::SECOND;

        return $this;
    }