Inserts new intervals at the specified offset of the sequence.

The sequence is re-indexed after addition

@param Period ...$intervals

@throws InvalidIndex If the offset is illegal for the current sequence.
547140
public function insert(int $offset, Period $interval, Period ...$intervals): void
    {
        if ($offset < 0 || $offset > count($this->intervals)) {
            throw new InvalidIndex(sprintf('%s is an invalid offset in the current sequence', $offset));
        }

        array_unshift($intervals, $interval);
        array_splice($this->intervals, $offset, 0, $intervals);
    }
1335159
public function offsetSet($index, $newval)
    {
        if ($newval instanceof $this->type) {
            parent::offsetSet($index, $newval);

            return;
        }

        if ($this->allowedTypes[$this->type]($newval)) {
            parent::offsetSet($index, $newval);

            return;
        }

        throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__CLASS__.' must be of the type '.$this->type.'.');
    }
794842
public function add(DateInterval $interval)
	{
		return $this->modify(
			function (\DateTime $datetime) use ($interval)
			{
				$datetime->add($interval->getDateInterval());
			}
		);
	}
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;
    }
1099929
@ReflectiveAccess
    protected void setInterval(String interval) {
        this.interval = ConversionService.SHARED.convert(interval, Duration.class).orElseThrow(() -> new IllegalArgumentException("Invalid Duration Specified"));
    }
68841
public function insert_range( $index, array $elements ) {
		$this->validate_index( $index );
		$this->type->validate_elements( $elements );

		if ( $index < 0 ) {
			$index = $this->count() + $index + 1;
		}

		return $this->new_from_trusted(
			array_merge(
				array_slice( $this->elements, 0, $index ),
				$elements,
				array_slice( $this->elements, $index, count( $this->elements ) )
			)
		);
	}
417010
private final function prepInterval( array $interval, &$error = null )
    {

        $error = null;

        if( $interval === array('') ) {
            return null;
        }

        if( $interval === array(null) ) {
            $this->containsNull = true;
            return null;
        }

        // cast interval to correct type
        foreach( $interval as &$value ) {
            if( !$this->cast( $value, $error ) ) {
                return null;
            }
        }

        switch( count( $interval ) ) {

            case 1:
                $interval[1] = $interval[0];
                break;

            case 2:

                if( $interval[0] !== null and $interval[1] !== null ) {
                    usort( $interval, array( $this, 'sort' ) );
                }
                break;

            default:
                $error = "too many fragments";
                return null;

        }

        return $interval;

    }
320660
public function push(Period $interval, Period ...$intervals): void
    {
        $this->intervals = array_merge($this->intervals, [$interval], $intervals);
    }
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;
	}
843184
public function add(TimeInterval $interval)
    {
        $date = clone $this->date;
        $int = new DateInterval($interval->intervalSpec());
        $date->add($int);
        return $this->dateTimeToTimePoint($date);
    }
218068
public function addOrders( $orders )
	{
		if( !is_array( $orders ) )
			throw new InvalidArgumentException( 'An Array should be given.' );
		foreach( $orders as $column => $direction )
			$this->addOrder( $column, $direction );
	}
838464
public function addTables( $tables, $prefix = NULL )
	{
		if( !is_array( $tables ) )
			throw new InvalidArgumentException( 'An Array should be given.' );
		$tables	= (array) $tables;
		foreach( $tables as $table )
			$this->addTable( $table, $prefix );
	}
60374
protected function modifyFromInterval($interval, $invert = false)
	{
		if ($invert)
		{
			$this->sub($interval);
		}
		else
		{
			$this->add($interval);
		}

		return $this;
	}
384591
public function add($interval)
    {
        if (self::$_immutable) {
            self::$_immutable = false;
            $newDate = clone $this;
            $newDate->add($interval);
            self::$_immutable = true;

            return $newDate;
        } else {
            return parent::add($interval);
        }
    }
770411
public function addPeriodicTimer(int $interval, callable $callback): void
    {
        $this->loop->addPeriodicTimer($interval, $callback);
    }
616634
public function compute(Intervals $firstInterval, Intervals $secondInterval): Intervals
    {
        $first  = $firstInterval->getArrayCopy();
        $second = $secondInterval->getArrayCopy();
        if (0 === count($second)) {
            return $firstInterval;
        }

        $count = count($second);
        while ($count > 0) {
            $intervalToExclude = \array_shift($second);

            $newIntervals = [];

            /** @var Interval $interval */
            foreach ($first as $interval) {
                $newIntervals = \array_merge($newIntervals, $interval->exclude($intervalToExclude)->getArrayCopy());
            }

            $first                   = $newIntervals;
            $count                   = count($second);
        }

        return new Intervals($first);
    }
272991
public function add(\DateInterval $interval)
    {
        $this->startDate->add($interval);
        $this->endDate->add($interval);

        return $this;
    }