Create a DateInterval from an PHP Dateinterval

@param DateInterval $interval
@return DateInterval
10621
public static function createFromDateInterval(\DateInterval $interval) {
    if ($interval instanceof DateInterval) return $interval;
    
    $ret = new DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
    $ret->invert = $interval->invert;
      
    return $ret;
  }
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}"));
        }
    }
341694
public function changeInterval($id, $interval) {
        return $this->webService->post("UPDATE 'PUSH'.'PUSHINTERVAL'", [
            self::PARAMETER_PUSH_ID => $id,
            self::PARAMETER_PUSH_INTERVAL => $interval
        ]);
    }
394328
public function withIntervalInSeconds($intervalInSeconds)
    {
        $this->validateInterval($intervalInSeconds);

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

        return $this;
    }
583025
private function copy(\DateInterval $interval)
	{
		$copy = new \DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
		$copy->invert = $interval->invert;

		return $copy;
	}
795991
public function sub(/*\DateInterval*/ $interval) : \DateTime /*self invariant*/
    {
        // NB: Argument type hinting (\DateInterval $interval)
        // would provoke E_WARNING when cloning.
        // Catch 22: Specs say that native \DateTime method is type hinted,
        // but warning when cloning says it isn't.

        if ($this->frozen) {
            throw new \RuntimeException(get_class($this) . ' is read-only, frozen.');
        }
        return parent::sub($interval);
    }
1280383
public function setInterval($interval)
    {
        $this->interval = $interval instanceof DateInterval ? $interval : new DateInterval($interval);
        return $this;
    }
1256377
private function parseDateInterval($interval)
    {
        try {
            if (!$this->isInstanceOf($interval, 'DateInterval')) {
                $interval = new StringObject($interval);
                if ($interval->startsWith('P')) {
                    $interval = new \DateInterval($interval);
                } else {
                    $interval = \DateInterval::createFromDateString($interval);
                }
            }
        } catch (\Exception $e) {
            throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_INTERVAL, [$interval]);
        }

        return $interval;
    }
1085501
static function convertInterval(DateInterval $d) {
		$i = 0;
		$i += $d->s;
		$i += $d->i * self::MINUTE;
		$i += $d->h * self::HOUR;
		$i += $d->d * self::DAY;
		$i += $d->m * self::MONTH;
		$i += $d->y * self::YEAR;

		return $i;
	}
673081
protected function _getInterval($interval) {
		if ($interval !== null) {
			return $interval;
		} elseif (!empty($this->params['interval'])) {
			return $this->params['interval'];
		} else {
			return '1 day';
		}
	}
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);
        }
    }
1138768
protected function dateIntervalToSeconds($interval): int
    {
        $now = time();
        $dt = new \DateTime();
        $dt->add($interval);
        $ts = $dt->getTimestamp();
        $diff = $ts - $now;
        return $diff;
    }
136692
public function withIntervalInDays($intervalInDays)
    {
        $this->validateInterval($intervalInDays);
        $this->interval = $intervalInDays;
        $this->intervalUnit = IntervalUnit::DAY;

        return $this;
    }
104304
function convertIntervalToCronTime(interval) {
  const intervalIsEmpty = interval.length === 0;
  const intervalIsTooBig = interval.length > 6;

  if (intervalIsEmpty){
    throw new Error(`The interval can not be empty`);
  } else if (intervalIsTooBig) {
    throw new Error('The interval can not contain more than 6 ranges');
  }

  const timeArray = fillInterval(interval);

  try {
    timeArray[0] = getSecond(timeArray[0]);
    timeArray[1] = getMinute(timeArray[1]);
    timeArray[2] = getHour(timeArray[2], timeArray[1]);
    timeArray[3] = getDayOfMonth(timeArray[3]);
    timeArray[4] = getMonth(timeArray[4]);
    timeArray[5] = getDayOfWeek(timeArray[5]);
  } catch (error){
    throw error;
  }

  const cronTime = `${timeArray[0]} ${timeArray[1]} ${timeArray[2]} ${timeArray[3]} ${timeArray[4]} ${timeArray[5]}`;
  return cronTime;
}
248087
public function isDateWillComeIn($interval)
    {
        if (!($interval instanceof \DateInterval)) {
            $interval = new \DateInterval((string) $interval);
        }
        $now = new \DateTime('now');
        return 0 === $this->diff($now->add($interval))->invert;
    }
1027827
final public static function intervalToSeconds($interval)
    {
        try {
            $start = new \DateTimeImmutable();
            $end = $start->add($interval);
            return $end->getTimestamp() - $start->getTimestamp();
        } catch (\Exception $e) {
            return 0;
        }

    }
1154278
public static function startOf($interval, \DateTime $date = null) {
			$date = $date ?: new \DateTime();

			switch ($interval) {
				case self::INTERVAL_MINUTE:
					$date->setTime((int)$date->format('H'), (int)$date->format('i'), 0, 0);

					break;

				case self::INTVERAL_HOUR:
					$date->setTime((int)$date->format('H'), 0, 0, 0);

					break;

				case self::INTERVAL_DAY:
					$date->setTime(0, 0, 0, 0);

					break;

				case self::INTERVAL_WEEK:
					$date
						->sub(new \DateInterval('P' . (int)$date->format('w') . 'D'))
						->setTime(0, 0, 0, 0);

					break;

				case self::INTERVAL_MONTH:
					$date
						->sub(new \DateInterval('P' . ((int)$date->format('d') - 1) . 'D'))
						->setTime(0, 0, 0, 0);

					break;

				case self::INTERVAL_YEAR:
					$date
						->setTime(0, 0, 0, 0)
						->setDate((int)$date->format('Y'), 1, 1);

					break;

				default:
					throw new \InvalidArgumentException('$interval must be one of the INTERVAL_* class constants');
			}

			return $date;
		}