@param \DateInterval $interval
@param int $parts

@return string
170568
final public static function formatInterval($interval, $parts = 0)
    {
        $interval = self::recalculateInterval($interval);

        $format = [];
        if ($interval->y !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{y,plural,one{# year} few{# years} many{# years} other{# years}}',
                ['y' => $interval->y]
            );
        }

        if ($interval->m !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{m,plural,one{# month} few{# months} many{# months} other{# months}}',
                ['m' => $interval->m]
            );
        }

        if ($interval->d !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{d,plural,one{# day} few{# days} many{# days} other{# days}}',
                ['d' => $interval->d]
            );
        }

        if ($interval->h !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{h,plural,one{# hour} few{# hours} many{# hours} other{# hours}}',
                ['h' => $interval->h]
            );
        }

        if ($interval->i !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{i,plural,one{#minute} few{# minutes} many{# minutes} other{# minutes}}',
                ['i' => $interval->i]
            );
        }

        if ($interval->s !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{s,plural,one{# second} few{# seconds} many{# seconds} other{# seconds}}',
                ['s' => $interval->s]
            );
        }

        if (count($format) === 0) {
            return "";
        }

        if (($parts > 0) && (count($format) > 1)) {
            $values = [];
            while ((count($values) < $parts) && (count($format) > 0)) {
                $values[] = array_shift($format);
            }
        } else {
            $values = $format;
        }

        return implode(" ", $values);
    }
1268410
public function sub(DateInterval $interval)
	{
		return $this->modify(
			function (\DateTime $datetime) use ($interval)
			{
				$datetime->sub($interval->getDateInterval());
			}
		);
	}
817359
protected static function intervalHasTime(DateInterval $interval)
    {
        // The array_key_exists and get_object_vars are used as a workaround to check microsecond support.
        // Both isset and property_exists will fail on PHP 7.0.14 - 7.0.21 due to the following bug:
        // https://bugs.php.net/bug.php?id=74852
        return $interval->h || $interval->i || $interval->s || array_key_exists('f', get_object_vars($interval)) && $interval->f;
    }
989856
public function toSeconds(\DateInterval $interval = null)
    {
        if ((null === $interval) && isset($this)) {
            $interval = $this;
        }

        $seconds = (string) $interval->s;

        if ($interval->i) {
            $seconds = bcadd($seconds, bcmul($interval->i, self::SECONDS_MINUTE));
        }

        if ($interval->h) {
            $seconds = bcadd($seconds, bcmul($interval->h, self::SECONDS_HOUR));
        }

        if ($interval->d) {
            $seconds = bcadd($seconds, bcmul($interval->d, self::SECONDS_DAY));
        }

        if ($interval->m) {
            $seconds = bcadd($seconds, bcmul($interval->m, self::SECONDS_MONTH));
        }

        if ($interval->y) {
            $seconds = bcadd($seconds, bcmul($interval->y, self::SECONDS_YEAR));
        }

        return $seconds;
    }
1174785
public static function generateQueryString(array $parts)
    {
        $return = "";

        foreach ($parts as $part) {
            if ($part instanceof Column) {
                if ($part->getColumnName() === '*') {
                    $return .= "*";
                } else {
                    $return .= "`{$part->getColumnName()}`"; // @codeCoverageIgnore
                }

                if ($part->getColumnAs() !== null) {
                    $return .= " " . $part->getColumnAs(); // @codeCoverageIgnore
                }

                $return .= ",";
            }
        }

        return ($return !== "" ? substr($return, 0, -1) : "*");
    }
583025
private function copy(\DateInterval $interval)
	{
		$copy = new \DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
		$copy->invert = $interval->invert;

		return $copy;
	}
969828
private function getSeconds(DateInterval $interval)
    {
        $date = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
        $date2 = $date->add($interval);
        return $date2->getTimestamp() - $date->getTimestamp();
    }
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}"));
        }
    }
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);
    }
13258
public function getOffsetDates($format, $interval = 30)
    {
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string')
            //argument 2 must be an integer
            ->test(2, 'int');

        $dates = array();
        $interval *= 60;

        for ($i=-12*3600; $i <= (12*3600); $i+=$interval) {
            $time = $this->time + $i;
            $dates[$i] = date($format, $time);
        }

        return $dates;
    }
209814
public static function intervalToTime(DateInterval $interval)
    {
        $time = null;

        if (!is_null($interval)) {
            $format = property_exists(get_class($interval), 'u') ? '%H:%I:%S.%U' : '%H:%I:%S';
            $time = $interval->format($format);
        }

        return $time;
    }
455997
protected function processParts(array $parts)
    {
        $strValue = '';
        foreach ($parts as $part) {
            $strValue .= $part->getValue();
        }
        return [$this->partFactory->newDatePart($strValue)];
    }
193310
public static function getSecondsByInterval(\DateInterval $dateInterval)
    {
        $dateTime = new DateTime;
        $dateTime->add($dateInterval);
        return $dateTime->getTimestamp() - time();
    }
941561
protected function determineMonth(DateLexerResult $parts)
    {
        // m   Numeric representation of a month, with leading zeros   01 through 12
        // n   Numeric representation of a month, without leading zeros
        if (null !== $m = $parts->getFirst('m', 'n')) {
            return (int)$m - 1;
        }
        // F   A full textual representation of a month, such as January or March
        // M   A short textual representation of a month, three letters
        if (null !== $m = $parts->getFirst('F', 'M')) {
            return (int)$m;
        }
    }
43334
public function toTime(Time $interval = null)
    {
        $secInDay = Time::days(1)->sec;
        $interval = $interval ? $interval->sec : $secInDay;

        return Time::sec(($this->deg / 360) * $interval);
    }
450344
protected function resolveBaseFormat(\DateInterval $interval): string
    {
        $format = '';

        if ($interval->y > 0) {
            $format .= '%yY';
        }

        if ($interval->m > 0) {
            $format .= '%mM';
        }

        if ($interval->d > 0) {
            $format .= '%dD';
        }

        return $format;
    }
835886
public function parse(string $input): \DateInterval
    {
        $input = trim($this->normalizer->normalize($input));

        $definition = Pattern::DEFINE . Pattern::INTEGER . Pattern::TIME_PART . ')';
        $expression = $definition . Pattern::INTERVAL_ONLY;

        if (preg_match($expression, $input, $matches)) {
            return \DateInterval::createFromDateString($input);
        }

        throw new FormatException("Given string is not a valid time interval.");
    }