将一个 \DateInterval，与当前时间进行计算，获取毫秒数

@param \DateInterval $dateInterval
@return int
193310
public static function getSecondsByInterval(\DateInterval $dateInterval)
    {
        $dateTime = new DateTime;
        $dateTime->add($dateInterval);
        return $dateTime->getTimestamp() - time();
    }
548975
protected function generateDateIntervalXML(DateInterval $dateInterval)
    {
        // Constructing XML structure
        $doc = new DOMDocument('1.0', 'utf-8');
        $root = $doc->createElement('adjustment');

        $year = $doc->createElement('year');
        $year->setAttribute('value', $dateInterval->format('%y'));
        $root->appendChild($year);
        unset($year);

        $month = $doc->createElement('month');
        $month->setAttribute('value', $dateInterval->format('%m'));
        $root->appendChild($month);
        unset($month);

        $day = $doc->createElement('day');
        $day->setAttribute('value', $dateInterval->format('%d'));
        $root->appendChild($day);
        unset($day);

        $hour = $doc->createElement('hour');
        $hour->setAttribute('value', $dateInterval->format('%h'));
        $root->appendChild($hour);
        unset($hour);

        $minute = $doc->createElement('minute');
        $minute->setAttribute('value', $dateInterval->format('%i'));
        $root->appendChild($minute);
        unset($minute);

        $second = $doc->createElement('second');
        $second->setAttribute('value', $dateInterval->format('%s'));
        $root->appendChild($second);
        unset($second);

        $doc->appendChild($root);

        return $doc->saveXML();
    }
1087617
final public static function recalculateInterval($interval)
    {
        try {
            $from = new \DateTimeImmutable();
            $to = $from->add($interval);
            $diff = $to->diff($from);
            foreach ($diff as $k => $v) {
                $interval->$k = $v;
            }

        } catch (\Exception $e) {
        }

        return $interval;
    }
843184
public function add(TimeInterval $interval)
    {
        $date = clone $this->date;
        $int = new DateInterval($interval->intervalSpec());
        $date->add($int);
        return $this->dateTimeToTimePoint($date);
    }
971596
public function wasWithinLast($timeInterval)
    {
        $now = new static();
        $interval = $now->copy()->modify('-' . $timeInterval);
        $thisTime = $this->format('U');

        return $thisTime >= $interval->format('U') && $thisTime <= $now->format('U');
    }
272991
public function add(\DateInterval $interval)
    {
        $this->startDate->add($interval);
        $this->endDate->add($interval);

        return $this;
    }
409762
private function fullDiff() : DateInterval
    {
        if (null === $this->fullDiff) {
            $this->fullDiff = $this->from->diff($this->until);
        }
        
        return $this->fullDiff;
    }
1101729
public static function toSecondsUsingDays(\DateInterval $interval)
    {
        $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 ((false !== $interval->days) && (0 <= $interval->days)) {
            $seconds = bcadd($seconds, bcmul($interval->days, self::SECONDS_DAY));
        } else {
            throw new InvalidArgumentException(
                'The "days" property is not set.'
            );
        }

        return $seconds;
    }
898806
public function getProductsInModifiedInterval(int $siteId, \DateTimeInterface $dateStart, \DateTimeInterface $dateEnd) : array
    {
        Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive');
        Assert::that($dateStart)->lessThan($dateEnd, '$dateStart has to be before $dateEnd');

        return (array)$this->master->doRequest(
            'GET',
            sprintf(
                '/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/GetByModifiedInterval/%d?start=%s&end=%s',
                $siteId,
                $dateStart->format('Y-m-d\TH:i:s'),
                $dateEnd->format('Y-m-d\TH:i:s')
            )
        );
    }
927938
private static function resolveDateInterval($interval) : \DateInterval
    {
        if ($interval instanceof DateInterval) {
            return $interval->toInternalDateInterval();
        }
        
        if (is_string($interval)) {
            return new \DateInterval($interval);
        }
        
        if ($interval instanceof \DateInterval) {
            return $interval;
        }
        
        throw new \InvalidArgumentException('Interval must be a string or an instance of DateInterval.');
    }
31127
public function setDateFormat($format = null, $dateIntervalFormat = null)
    {
        if (null !== $format) {
            $this->dateFormats[0] = $format;
        }

        if (null !== $dateIntervalFormat) {
            $this->dateFormats[1] = $dateIntervalFormat;
        }
    }
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;
    }
776947
public function add($date, $interval)
    {
        if (!$interval instanceof \DateInterval) {
            $interval = new \DateInterval($interval);
        }
        $result = clone $date;
        return $result->add($interval);
    }
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;
    }
27747
public function formatInterval(\DateInterval $dateInterval): string
    {
        $format = 'P';

        if (0 < $dateInterval->y) {
            $format .= $dateInterval->y.'Y';
        }

        if (0 < $dateInterval->m) {
            $format .= $dateInterval->m.'M';
        }

        if (0 < $dateInterval->d) {
            $format .= $dateInterval->d.'D';
        }

        if (0 < $dateInterval->h || 0 < $dateInterval->i || 0 < $dateInterval->s) {
            $format .= 'T';
        }

        if (0 < $dateInterval->h) {
            $format .= $dateInterval->h.'H';
        }

        if (0 < $dateInterval->i) {
            $format .= $dateInterval->i.'M';
        }

        if (0 < $dateInterval->s) {
            $format .= $dateInterval->s.'S';
        }

        return $format;
    }
345086
protected function decodeIntervalSpec(): void
    {
        $this->di = new DateInterval($this->expression);
        $this->time = (new DateTime('@0'))
            ->add($this->di)
            ->getTimestamp();
    }
796436
protected function ttlToTimestamp($ttl): ?int
    {
        if (!isset($ttl)) {
            return isset($this->ttl) ? time() + $this->ttl : null;
        }

        if (is_int($ttl)) {
            return time() + (isset($this->ttl) ? min($ttl, $this->ttl) : $ttl);
        }

        if ($ttl instanceof DateInterval) {
            $timestamp = (new DateTimeImmutable())->add($ttl)->getTimestamp();

            return isset($this->ttl) ? min($timestamp, time() + $this->ttl) : $timestamp;
        }

        $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
        throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
    }