Calculate seconds from interval

@param DateInterval $interval

@return int
760201
private function intervalToSeconds(DateInterval $interval): int
    {
        $seconds = (int) $interval->format('%s');

        $multiplier = 60;
        $seconds += (int) $interval->format('%i') * $multiplier;

        $multiplier *= 60;
        $seconds += (int) $interval->format('%h') * $multiplier;

        $multiplier *= 24;
        $seconds += (int) $interval->format('%d') * $multiplier;

        $multiplier *= 30;
        $seconds += (int) $interval->format('%m') * $multiplier;

        $multiplier *= 12;
        $seconds += (int) $interval->format('%y') * $multiplier;

        return $seconds;
    }
1280199
public static function instance(DateInterval $di)
    {
        if (self::wasCreatedFromDiff($di)) {
            throw new InvalidArgumentException('Can not instance a Interval object created from DateTime::diff().');
        }

        $instance = new static($di->y, $di->m, 0, $di->d, $di->h, $di->i, $di->s);
        $instance->invert = $di->invert;
        $instance->days = $di->days;

        return $instance;
    }
721591
public static function addInterval($interval, $format = self::DEFAULT_TIME_FORMAT)
    {
        $date = Clock::now()->toDateTime();
        $date->add(new DateInterval($interval));
        return $date->format($format);
    }
487725
public function add($interval)
    {
        parent::add($interval);

        if ($interval instanceof DateInterval) {
            if ($interval->invert) { // is negative, then sub
                $this->subMicroseconds($interval->u);
            } else {
                $this->addMicroseconds($interval->u);
            }
        }

        return $this;
    }
854305
public function findVisitsHours(Range $interval): ?Result
	{
		$this->checkVisits($interval);
		return $this->orm->trackingVisits->findVisitsHours($interval);
	}
341735
public function withIntervalInMinutes($intervalInMinutes)
    {
        $this->validateInterval($intervalInMinutes);
        $this->interval = $intervalInMinutes;
        $this->intervalUnit = IntervalUnit::MINUTE;

        return $this;
    }
193310
public static function getSecondsByInterval(\DateInterval $dateInterval)
    {
        $dateTime = new DateTime;
        $dateTime->add($dateInterval);
        return $dateTime->getTimestamp() - time();
    }
294223
public function findVisitsHours(Range $interval, bool $useTime = false): ?Result
	{
		$date = $useTime ? '%dt' : 'DATE(%dt)';

		$subQuery = 'SELECT '
			. 'DATE_FORMAT([inserted], "%%Y-%%m-%%d %%H:00:00") datefield, '
			. 'COUNT([uid]) visits '
			. 'FROM %table '
			. 'WHERE ' . ($useTime ? '[inserted]' : 'DATE([inserted])') . ' BETWEEN ' . $date . ' AND ' . $date . ' '
			. 'GROUP BY [uid], ROUND(UNIX_TIMESTAMP([inserted]) / %i)';
		return $this->connection->query('SELECT [datefield], COUNT([visits]) visits FROM (' . $subQuery . ') sub GROUP BY HOUR([datefield]), DAY([datefield])', $this->getTableName(), $interval->from, $interval->to, $this->minTimeBetweenVisits * 60);
	}
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;
    }
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;
    }
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());
        }

    }
609663
public function setExpires($period)
    {
        if (is_int($period))
            return $this->setExpiresInSeconds($period);
        if ($period instanceof DateTimeInterface)
            return $this->setExpireDate($period);
        if ($period instanceof DateInterval)
            return $this->setExpiresIn($period);

        throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required");
    }
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;
    }
776947
public function add($date, $interval)
    {
        if (!$interval instanceof \DateInterval) {
            $interval = new \DateInterval($interval);
        }
        $result = clone $date;
        return $result->add($interval);
    }
1317577
private function diffInUnits(DateInterval $interval, $detailLevel)
	{
		$units = array('y' => 'year', 'm' => 'month', 'd' => 'day',
			'h' => 'hour', 'i' => 'minute', 's' => 'second'
		);

		$diff = array();

		foreach ($units as $format => $unit)
		{
			$amount = $interval->format('%' . $format);

			/** Adding support for weeks */
			if ($unit == 'day' && $amount >= 7)
			{
				$weeks = floor($amount / 7);
				$amount -= $weeks * 7;
				$diff[] = array(
					'amount' => $weeks,
					'unit' => 'week'
				);

				$detailLevel--;
			}

			// Save only non-zero units of time
			if ($amount > 0 && $detailLevel > 0)
			{
				$diff[] = array(
					'amount' => $amount,
					'unit' => $unit
				);

				$detailLevel--;
			}

			if ($detailLevel === 0)
			{
				break;
			}
		}

		return $diff;
	}
677433
public function setExpiresIn(DateInterval $interval)
    {
        $this->expires = new DateTime();
        $this->expires->add($interval);
        return $this;
    }
11686
public function add(/*\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::add($interval);
    }