Returns the highest unit and its value in a diff.

@param \DateInterval $diff
@return array
436856
protected function getHighestDiffUnitAndValue($diff)
    {
        // Manually define props due to Reflection Bug #53439 (PHP)
        $properties = array('y', 'm', 'd', 'h', 'i', 's');

        foreach($properties as $prop) {
            if ($diff->$prop > 0) {
                return array('unit' => $prop, 'value' => $diff->$prop);
            }
        }

        return array('unit' => 'now', 'value' => 0);
    }
603809
public static function dateIntervalToIntervalSpec(DateInterval $di): string
    {
        $time_parts = ['h', 'i', 's', 'f'];
        $time_token_set = false;
        $interval_spec = 'P';

        foreach (array_keys(self::$tokens) as $token) {
            if (in_array($token, $time_parts) && $time_token_set === false && $di->$token > 0) {
                $interval_spec .= 'T';
                $time_token_set = true;
            }
            if ($di->$token > 0) {
                $token_string = $token;
                if (array_key_exists($token, self::$tokensSubstitution)) {
                    $token_string = self::$tokensSubstitution[$token];
                }
                $interval_spec .= $di->$token.strtoupper($token_string);
            }
        }

        return $interval_spec;
    }
583025
private function copy(\DateInterval $interval)
	{
		$copy = new \DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
		$copy->invert = $interval->invert;

		return $copy;
	}
500083
private function getDifference($value): ?int
    {
        // Let's prepare the dates...
        $now = (new \DateTime())->setTime(0, 0);
        $date = Date::getDateTime($value);

        // ...and make comparison with "day" as unit
        if ($date instanceof \DateTime) {
            return Date::getDateDifference($now, $date, Date::DATE_DIFFERENCE_UNIT_DAYS);
        }

        return null;
    }
105573
public function diff($time) : DateInterval
    {
        $tmp = new self($time);

        return new DateInterval(abs($this->time - $tmp->getUnixTstamp()));
    }
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;
    }
1158466
protected function getSeconds($delay)
	{
		if ($delay instanceof DateTime)
		{
			return max(0, $delay->getTimestamp() - $this->getTime());
		}
		else
		{
			return intval($delay);
		}
	}
955508
public function farthest(ChronosInterface $dt1, ChronosInterface $dt2)
    {
        return $this->diffInSeconds($dt1) > $this->diffInSeconds($dt2) ? $dt1 : $dt2;
    }
318620
public function getDifferenceInSeconds($compare = null)
        {
            if (!$compare) {
                $compare = new Date(null, $this->getTimezone());
            }

            $difference = $this->diff($compare);

            list($days, $hours, $minutes, $seconds) = explode(':', $difference->format('%a:%h:%i:%s'), 4);

            // Add the total amount of seconds in all the days.
            $seconds += ($days * 24 * 60 * 60);

            // Add the total amount of seconds in all the hours.
            $seconds += ($hours * 60 * 60);

            // Add the total amount of seconds in all the minutes.
            $seconds += ($minutes * 60);

            return $seconds * $difference->format('%r1');
        }
1048965
public function substract(DatePeriodDateTime $comparison) : array
    {
        $start = $this;
        $end = $this->getEndDate();

        $comparisonStart = $comparison;
        $comparisonEnd = $comparison->getEndDate();

        /*
         *            L     H
         * C :        |_____|
         * 1 :      __|__   |
         * 2 :     ___|     |
         * 3 :        |   __|___
         * 4 :        |     |___
         * 5 :      __|_____|__
         * 6 :        |_____|___
         * 7 :      __|_____|
         * 8 :        |_____|
         * 9 :   __   |     |
         * 10:        |     | __
         * 11:        |  __ |
         */

        // case 1
        if ($start->lt($comparisonStart) && $comparisonStart->gt($start) && $end->lt($comparisonEnd) && $end->gt($comparisonStart)) {
            return [new static($start, $comparisonStart)];
        }

        // case 2
        if ($end->eq($comparisonStart)) {
            return [$this];
        }

        // case 3
        if ($start->gt($comparisonStart) && $start->lt($comparisonEnd) && $end->gt($comparisonEnd)) {
            return [new static($comparisonEnd, $end)];
        }

        // case 4
        if ($start->eq($comparisonEnd)) {
            return [$this];
        }

        // case 5
        if ($start->lt($comparisonStart) && $end->gt($comparisonEnd)) {
            return [new static($start, $comparisonStart), new static($comparisonEnd, $end)];
        }

        // case 6
        if ($start->eq($comparisonStart) && $end->gt($comparisonEnd)) {
            return [new static($comparisonEnd, $end)];
        }

        // case 7
        if ($start->lt($comparisonStart) && $end->eq($comparisonEnd)) {
            return [new static($start, $comparisonStart)];
        }

        // case 8
        if ($start->eq($comparisonStart) && $end->eq($comparisonEnd)) {
            return [];
        }

        // case 11
        if ($start->gt($comparisonStart) && $end->lt($comparisonEnd)) {
            return [];
        }

        return [$this];
    }
1138768
protected function dateIntervalToSeconds($interval): int
    {
        $now = time();
        $dt = new \DateTime();
        $dt->add($interval);
        $ts = $dt->getTimestamp();
        $diff = $ts - $now;
        return $diff;
    }
409762
private function fullDiff() : DateInterval
    {
        if (null === $this->fullDiff) {
            $this->fullDiff = $this->from->diff($this->until);
        }
        
        return $this->fullDiff;
    }
617303
private static function getSpecString(\DateInterval $delta)
    {
        $date = array_filter(['Y' => $delta->y, 'M' => $delta->m, 'D' => $delta->d]);
        $time = array_filter(['H' => $delta->h, 'M' => $delta->i, 'S' => $delta->s]);

        foreach ($date as $key => &$value) {
            $value = $value.$key;
        }
        foreach ($time as $key => &$value) {
            $value = $value.$key;
        }

        $spec = 'P'.implode('', $date);

        if (count($time) > 0) {
            $spec .= 'T'.implode('', $time);
        }

        return $spec;
    }
25562
public static function getSecondsFromInterval(DateInterval $interval)
    {
        $map   = [31536000, 2592000, 86400, 3600, 60, 1];
        $parts = explode('.', $interval->format('%y.%m.%d.%h.%i.%s'));
        $value = 0;

        foreach ($parts as $key => $val) {
            $value+= $val * $map[$key];
        }

        return $value;
    }
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;
    }
532301
public function max(ChronosInterface $dt = null)
    {
        $dt = ($dt === null) ? static::now($this->tz) : $dt;

        return $this->gt($dt) ? $this : $dt;
    }
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;
    }