Adds an amount of days, months, years, hours, minutes, seconds and microseconds to a DateTime object

@param DateInterval $interval
@return DateTime $this
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;
    }
412923
public function subtract($date, $interval)
    {
        if (!$interval instanceof \DateInterval) {
            $interval = new \DateInterval($interval);
        }
        $result = clone $date;
        return $result->sub($interval);
    }
193310
public static function getSecondsByInterval(\DateInterval $dateInterval)
    {
        $dateTime = new DateTime;
        $dateTime->add($dateInterval);
        return $dateTime->getTimestamp() - time();
    }
955398
public function add($interval = null)
	{
		if ( ! $interval instanceOf DateInterval)
		{
			if (is_numeric($interval))
			{
				$delta = intval($interval);
				$interval = new DateInterval('PT'.strval(abs($delta)).'S');
				if ($delta < 0)
				{
					$interval->invert = 1;
				}
			}
		}

		if ($this->datetime->add($interval))
		{
			return $this;
		}

		return false;
	}
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;
    }
1138073
public function addMinutes($minutes)
    {
        $minutes = (int) $minutes;
        $interval = new DateInterval('PT' . abs($minutes) . 'M');

        if ($minutes < 0) {
            $interval->invert = 1;
        }

        return $this->add($interval);
    }
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;
    }
1239719
public function withIntervalInMonths($intervalInMonths)
    {
        $this->validateInterval($intervalInMonths);
        $this->interval = $intervalInMonths;
        $this->intervalUnit = IntervalUnit::MONTH;

        return $this;
    }
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;
    }
362535
public function withIntervalInYears($intervalInYears)
    {
        $this->validateInterval($intervalInYears);
        $this->interval = $intervalInYears;
        $this->intervalUnit = IntervalUnit::YEAR;

        return $this;
    }
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();
    }
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());
        }

    }
770632
public static function dateAdd($interval, $value, $dateTime = null, $format = null): string
    {
        $dateTime = $dateTime ? $dateTime : date('Y-m-d H:i:s');
        $date = getdate(self::getTimestamp($dateTime));
        switch ($interval) {
            case 'Y' : // 年
                $date ['year'] += $value;
                break;
            case 'Q' : // 季度
                $date ['mon'] += ($value * 3);
                break;
            case 'M' : // 月
                $date ['mon'] += $value;
                break;
            case 'W' : // 星期
                $date ['mday'] += ($value * 7);
                break;
            case 'D' : // 日
                $date ['mday'] += $value;
                break;
            case 'H' : // 时
                $date ['hours'] += $value;
                break;
            case 'N' : // 分
                $date ['minutes'] += $value;
                break;
            case 'S' : // 秒
            default :
                $date ['seconds'] += $value;
                break;
        }
        return date($format, mktime($date ['hours'], $date ['minutes'], $date ['seconds'], $date ['mon'], $date ['mday'], $date ['year']));
    }
97484
public final function addHours( int $hours = 1 )
      : DateTime
   {

      return $this->move( new \DateInterval( 'PT' . \abs( $hours ) . 'H' ), $hours < 0 );

   }
843184
public function add(TimeInterval $interval)
    {
        $date = clone $this->date;
        $int = new DateInterval($interval->intervalSpec());
        $date->add($int);
        return $this->dateTimeToTimePoint($date);
    }
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;
    }
341735
public function withIntervalInMinutes($intervalInMinutes)
    {
        $this->validateInterval($intervalInMinutes);
        $this->interval = $intervalInMinutes;
        $this->intervalUnit = IntervalUnit::MINUTE;

        return $this;
    }