Get amount of seconds in date interval

@param DateInterval $interval
@return int
@throws \Exception
969828
private function getSeconds(DateInterval $interval)
    {
        $date = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
        $date2 = $date->add($interval);
        return $date2->getTimestamp() - $date->getTimestamp();
    }
97188
protected function resolveFormat(\DateInterval $interval): string
    {
        $baseFormat = $this->resolveBaseFormat($interval);
        $timeFormat = $this->resolveTimeFormat($interval);

        if ($baseFormat === '') {
            if ($timeFormat === '') {
                return '';
            }

            return 'PT' . $timeFormat;
        }

        if ($timeFormat === '') {
            return 'P' . $baseFormat;
        }

        return 'P' . $baseFormat . 'T' . $timeFormat;
    }
304675
final public static function intervalToSpec($interval)
    {
        $interval = self::recalculateInterval($interval);

        $result = "P";
        if ($interval->y !== 0) {
            $result .= sprintf('%dY', $interval->y);
        }

        if ($interval->m !== 0) {
            $result .= sprintf('%dM', $interval->m);
        }

        if ($interval->d !== 0) {
            $result .= sprintf('%dD', $interval->d);
        }


        $timeMarkerSet = false;
        if ($interval->h !== 0) {
            if (!$timeMarkerSet) {
                $result .= 'T';
            }

            $result .= sprintf('%dH', $interval->h);
        }

        if ($interval->i !== 0) {
            if (!$timeMarkerSet) {
                $result .= 'T';
            }

            $result .= sprintf('%dM', $interval->i);
        }

        if ($interval->s !== 0) {
            if (!$timeMarkerSet) {
                $result .= 'T';
            }

            $result .= sprintf('%dS', $interval->s);
        }

        if ($result == 'P') {
            return "";
        }

        return $result;
    }
495009
public function getCachedResult($interval)
    {
        if (!empty(self::$resultCache[$interval])) {
            return self::$resultCache[$interval];
        }
        return false;
    }
494882
public static function normalize($interval)
    {
        $from = new \DateTime("1970-01-01 00:00:00");
        $to = clone $from;
        $to = $to->add($interval);
        $result = $from->diff($to);

        return ($result !== false) ? $result : $interval;
    }
380861
public static function totalSeconds(DateInterval $interval)
    {
        $sYears = 31536000 * $interval->y;
        $sMonths = 30 * 24 * 3600 * $interval->m;
        $sDays = 24 * 3600 * $interval->d;
        $sHours = 3600 * $interval->h;
        $sMinutes = 60 * $interval->i;
        $sSeconds = $interval->s;

        $total = $sYears + $sMonths + $sDays + $sHours + $sMinutes + $sSeconds;

        return ($interval->invert === 1) ? $total * -1 : $total;
    }
965145
public function getFrame($interval)
	{
		if ( ! $interval instanceof TimeInterval)
		{
			$interval = new TimeInterval($interval);
		}
		
		if ($interval->getSeconds() > $this->getDuration())
		{
			throw new \OutOfRangeException('The interval may not be a more than '.$this->getDuration());
		}
		
		$frame = new Frame($this->getFilePath(), $this->getService());
		$frame->addFilter(new SimpleFilter(['seek_start' => $interval->__toString()]), 99);
		
		return $frame;
	}
843184
public function add(TimeInterval $interval)
    {
        $date = clone $this->date;
        $int = new DateInterval($interval->intervalSpec());
        $date->add($int);
        return $this->dateTimeToTimePoint($date);
    }
1155235
private function get_interval(string $interval = '')
  {
    if ( !empty($interval) ){
      $this->interval = new \DateInterval($interval);
      return $this->interval;
    }
    else {
      return $this->interval;
    }
  }
502341
public function getTempoEspera()
    {
        if ($this->tempoEspera) {
            return $this->secondsToDateInterval($this->tempoEspera);
        }
        
        $now = new DateTime();
        $interval = $now->diff($this->getDataChegada());

        return $interval;
    }
1126525
public function findVisitsDays(Range $interval): ?Result
	{
		$this->checkVisits($interval);
		return $this->orm->trackingVisits->findVisitsDays($interval);
	}
429845
private static function dateIntervalToString(\DateInterval $interval)
    {

        // Reading all non-zero date parts.
        $date = array_filter([
            'Y' => $interval->y,
            'M' => $interval->m,
            'D' => $interval->d,
        ]);

        // Reading all non-zero time parts.
        $time = array_filter([
            'H' => $interval->h,
            'M' => $interval->i,
            'S' => $interval->s,
        ]);

        $specString = 'P';

        // Adding each part to the spec-string.
        foreach ($date as $key => $value) {
            $specString .= $value.$key;
        }
        if (count($time) > 0) {
            $specString .= 'T';
            foreach ($time as $key => $value) {
                $specString .= $value.$key;
            }
        }

        return $specString;
    }
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;
        }

    }
548315
public static function format_retention_period(\DateInterval $interval) : string {
        // It is one or another.
        if ($interval->y) {
            $formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
        } else if ($interval->m) {
            $formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
        } else if ($interval->d) {
            $formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
        } else {
            $formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
        }

        return $formattedtime;
    }
193310
public static function getSecondsByInterval(\DateInterval $dateInterval)
    {
        $dateTime = new DateTime;
        $dateTime->add($dateInterval);
        return $dateTime->getTimestamp() - time();
    }
1302803
protected function calculateUnits(DateInterval $interval)
    {
        $units = array_filter(array(
            'years'   => (int) $interval->y,
            'months'  => (int) $interval->m,
            'days'    => (int) $interval->d,
            'hours'   => (int) $interval->h,
            'minutes' => (int) $interval->i,
            'seconds' => (int) $interval->s,
        ));

        if (empty($units)) {
            return array();
        } else if ((int) $this->config['truncate'] > 0) {
            return array_slice($units, 0, (int) $this->config['truncate']);
        }

        return $units;
    }
1091377
private function dateDiff() : DateInterval
    {
        if (null === $this->dateDiff) {
            $this->dateDiff = $this->from->withTimeAtMidnight()->diff($this->until->withTimeAtMidnight());
        }
        
        return $this->dateDiff;
    }