Generates the internal XML structure for $dateInterval, used for date adjustment.

@param \DateInterval $dateInterval

@return string The generated XML string
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();
    }
746380
public function expiresAfter($timeInterval)
    {
        if ($timeInterval instanceof DateInterval) {
            $this->expire = (int) DateTime::createFromFormat('U', time())->add($timeInterval)->format('U');
        } elseif (is_numeric($timeInterval)) {
            $this->expire = $timeInterval + time();
        } else {
            throw new InvalidArgumentException('not support datetime');
        }

        return $this;
    }
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;
    }
45670
protected function decodeTimeString()
    {
        $di = DateInterval::createFromDateString($this->expression);
        $this->time = (new DateTime('@0'))
            ->add($di)
            ->getTimestamp();

        // force verification
        $this->di = new DateInterval($this->dateIntervalToIntervalSpec($di));
    }
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;
    }
1138768
protected function dateIntervalToSeconds($interval): int
    {
        $now = time();
        $dt = new \DateTime();
        $dt->add($interval);
        $ts = $dt->getTimestamp();
        $diff = $ts - $now;
        return $diff;
    }
948916
public function invert()
	{
		$interval = $this->copy($this->interval);
		$interval->invert = $interval->invert ? 0 : 1;

		return new DateInterval($interval);
	}
37731
protected function getDateIntervalFromXML($xmlText)
    {
        if (empty($xmlText)) {
            return;
        }

        $xml = new SimpleXMLElement($xmlText);
        $aIntervalString = array(
            (int)$xml->year['value'] . ' years',
            (int)$xml->month['value'] . ' months',
            (int)$xml->day['value'] . ' days',
            (int)$xml->hour['value'] . ' hours',
            (int)$xml->minute['value'] . ' minutes',
            (int)$xml->second['value'] . ' seconds',
        );

        return DateInterval::createFromDateString(implode(', ', $aIntervalString));
    }
345086
protected function decodeIntervalSpec(): void
    {
        $this->di = new DateInterval($this->expression);
        $this->time = (new DateTime('@0'))
            ->add($this->di)
            ->getTimestamp();
    }
703747
public static function instance(DateInterval $di)
    {
        $microseconds = $di->f;
        $instance = new static(static::getDateIntervalSpec($di));
        if ($microseconds) {
            $instance->f = $microseconds;
        }
        $instance->invert = $di->invert;
        foreach (['y', 'm', 'd', 'h', 'i', 's'] as $unit) {
            if ($di->$unit < 0) {
                $instance->$unit *= -1;
            }
        }

        return $instance;
    }
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;
	}
842805
public function toDateInterval() : \DateInterval
    {
        return \DateInterval::createFromDateString(\sprintf(
            '%d years %d months %d days',
            $this->years,
            $this->months,
            $this->days
        ));
    }
477049
public function getDateIntervalPropertyByUnit(DateInterval $diff, $unit)
    {
        if ($unit === 'seconds') {
            return $diff->s + $diff->i * 60 + $diff->h * 60 * 60 + $diff->days * 60 * 60 * 24;
        }

        if ($unit === 'minutes') {
            return $diff->i + $diff->h * 60 + $diff->days * 60 * 24;
        }

        if ($unit === 'hours') {
            return $diff->h + $diff->days * 24;
        }

        if ($unit === 'days') {
            return $diff->days;
        }

        if ($unit === 'months') {
            return $diff->m + $diff->y * 12;
        }

        if ($unit === 'years') {
            return $diff->y;
        }
    }
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);
    }
1280492
public function formatDate(\DateTimeInterface $dateTime, string $dateLength): string
    {
        $format = $this->getFormat($dateLength);

        return $dateTime->format($format);
    }
794842
public function add(DateInterval $interval)
	{
		return $this->modify(
			function (\DateTime $datetime) use ($interval)
			{
				$datetime->add($interval->getDateInterval());
			}
		);
	}
942769
public function days(DateInterval $diff)
    {
        if ($diff->days <= $this->max_days_count) {
            return $diff->days;
        }
        return false;
    }