@param string       $units
@param DateInterval $diff

@return mixed
359318
private function calculate($units, DateInterval $diff)
    {
        $calculator = [
            'centuries' => function (DateInterval $diff) {
                return $diff->y / 100;
            },
            'decades' => function (DateInterval $diff) {
                return $diff->y / 10;
            },
            'years' => function (DateInterval $diff) {
                return $diff->y;
            },
            'months' => function (DateInterval $diff) {
                return $diff->y * 12 + $diff->m;
            },
            'days' => function (DateInterval $diff) {
                return $diff->days;
            },
            'hours' => function (DateInterval $diff) {
                return ($diff->days * 24) + $diff->h;
            },
            'minutes' => function (DateInterval $diff) {
                return ($diff->days * 24 * 60) + $diff->i;
            },
            'seconds' => function (DateInterval $diff) {
                return ($diff->days * 24 * 60 * 60) + $diff->s;
            },
        ];
        $u = isset($calculator[$units]) ? $units : 'years';

        return $calculator[$u]($diff);
    }
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');
        }
1256487
public function getRelativeDate($compare = null)
        {
            if (!$compare) {
                $compare = new Date(null, $this->getTimezone());
            }

            $units = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
            $values = array(60, 60, 24, 7, 4.35, 12);

            // Get the difference between the two timestamps. We'll use this to calculate the actual time remaining.
            $difference = abs($compare->getTimestamp() - $this->getTimestamp());

            for ($i = 0 ; $i < count($values) && $difference >= $values[$i] ; $i++) {
                $difference = $difference / $values[$i];
            }

            // Round the difference to the nearest whole number.
            $difference = round($difference);

            if ($compare->getTimestamp() < $this->getTimestamp()) {
                $suffix = 'from now';
            } else {
                $suffix = 'ago';
            }

            // Get the unit of time we are measuring. We'll then check the difference, if it is not equal to exactly 1 then it's a multiple of the given unit so we'll append an 's'.
            $unit = $units[$i];

            if ($difference != 1) {
                $unit .= 's';
            }

            return $difference.' '.$unit.' '.$suffix;
        }
645490
protected function update_unit_pattern( array $units ) {
		// Update unit regex pattern.
		foreach ( $units as $index => $unit ) {
			$units[ $index ] = \preg_quote( $unit, '/' );
		}

		$custom_units  = \implode( '|', $units );
		$custom_units .= ! empty( $custom_units ) ? '|' : '';

		return $custom_units;
	}
952711
private function parseUnits($diff, $allowAlmost = false)
	{
		if (empty($diff))
		{
			return '';
		}

		$isAlmost = false;
		$string = array();

		foreach ($diff as $time)
		{
			if ($allowAlmost)
			{
				$isAlmost = $this->isAlmost($time);
			}

			$string[] = $this->translator->choice($time['unit'], $time['amount']);
		}

		$parsed = $string[0];

		// Add 'and' separator
		if (count($string) > 1)
		{
			$theLastOne = $string[count($string) - 1];
			unset($string[count($string) - 1]);

			$and = $this->translator->get('and');
			$parsed = sprintf('%s %s %s', implode(', ', $string), $and, $theLastOne);
		}

		if ($isAlmost)
		{
			$parsed = $this->translator->get('almost', array('time' => $parsed));
		}

		return $parsed;
	}
835826
public function getTimeUnitFromDateRange($dateFrom, $dateTo)
    {
        $dayDiff = $dateTo->diff($dateFrom)->format('%a');
        $unit    = 'd';

        if ($dayDiff <= 1) {
            $unit = 'H';

            $sameDay    = $dateTo->format('d') == $dateFrom->format('d') ? 1 : 0;
            $hourDiff   = $dateTo->diff($dateFrom)->format('%h');
            $minuteDiff = $dateTo->diff($dateFrom)->format('%i');
            if ($sameDay && !intval($hourDiff) && intval($minuteDiff)) {
                $unit = 'i';
            }
            $secondDiff = $dateTo->diff($dateFrom)->format('%s');
            if (!intval($minuteDiff) && intval($secondDiff)) {
                $unit = 'm';
            }
        }
        if ($dayDiff > 31) {
            $unit = 'W';
        }
        if ($dayDiff > 63) {
            $unit = 'm';
        }
        if ($dayDiff > 1000) {
            $unit = 'Y';
        }

        return $unit;
    }
842805
public function toDateInterval() : \DateInterval
    {
        return \DateInterval::createFromDateString(\sprintf(
            '%d years %d months %d days',
            $this->years,
            $this->months,
            $this->days
        ));
    }
213865
public static function dateIntervalToSeconds(\DateInterval $i){
		return $i->days * 86400 + $i->h * 3600 + $i->i * 60 + $i->s;
	}
182298
public static function turnDateIntervalToSeconds(DateInterval $dateInterval)
    {
        return $dateInterval->y * 365 * 24 * 3600
            + $dateInterval->m * 30 * 24 * 3600
            + $dateInterval->d * 24 * 3600
            + $dateInterval->h * 3600
            + $dateInterval->i * 60
            + $dateInterval->s;
    }
1302803
protected function calculateUnits(DateInterval $interval)
    {
        $units = array_filter(array(
            'years'   => (int) $interval->y,
            'months'  => (int) $interval->m,
            'days'    => (int) $interval->d,
            'hours'   => (int) $interval->h,
            'minutes' => (int) $interval->i,
            'seconds' => (int) $interval->s,
        ));

        if (empty($units)) {
            return array();
        } else if ((int) $this->config['truncate'] > 0) {
            return array_slice($units, 0, (int) $this->config['truncate']);
        }

        return $units;
    }
1068340
public static function createFromDateInterval(DateInterval $interval)
	{
		$obj = new self( 'PT0S' );
		foreach ( $interval as $property => $value ) {
			$obj->$property = $value;
		}
		return $obj;
	}
1166143
private function formatNormal(\DateInterval $diff)
    {
        $str = '';
        $first = null;
        $second = null;
        $val = 0;

        if ($diff->y > 0) {
            $str = "year";
            $val = $diff->y;
        } else if ($diff->m > 0) {
            $str = "month";
            $val = $diff->m;
        } else if ($diff->d > 0) {
            $str = "day";
            $first = array('after' => "tomorrow", 'before' => "yesterday");
            $val = $diff->d;
        } else if ($diff->h > 0) {
            $str = "hour";
            $val = $diff->h;
        } else if ($diff->i == 30) {
            var_dump($diff->invert);
            return $diff->invert ? $this->translator->trans("next half hour") : $this->translator->trans("half hour ago");
        } else if ($diff->i > 0) {
            $str = "minute";
            $val = $diff->i;
        } else if ($diff->s > 0) {
            $str = "second";
            $val = $diff->s;
        }

        $id = "%" . $str . "s%";

        if ($diff->invert) {
            return $this->translator->transChoice(
                ($first && isset($first['after']) ? $first['after'] : "next " . $str) . "|" .
                ($second && isset($second['after']) ? $second['after'] : "next " . $id . " " . $str . "s"), $val, array(
                $id => $val
            ));
        } else {
            return $this->translator->transChoice(
                ($first && isset($first['before']) ? $first['before'] : ($str == "hour" ? 'an' : 'a') . ' ' . $str . ' ago') . "|" .
                ($second && isset($second['before']) ? $second['before'] : $id . " " . $str . "s ago"), $val, array(
                $id => $val
            ));
        }
    }
969828
private function getSeconds(DateInterval $interval)
    {
        $date = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
        $date2 = $date->add($interval);
        return $date2->getTimestamp() - $date->getTimestamp();
    }
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;
    }
1209356
private function getChangedColumns($tableName, TableDiff $diff)
    {
        /** @var $col \Doctrine\DBAL\Schema\ColumnDiff */
        foreach ($diff->changedColumns as $col) {
            $this->addMessage($tableName, sprintf('invalid column `%s`', $col->oldColumnName));
        }
    }
703569
public function unit($number, $unit, $decimals = null)
    {
        $format = $this->getFormat(self::UNIT);
        $numeric = $this->number($number, $decimals);
        return str_replace(['{number}', '{unit}'], [$numeric, $unit], $format);
    }
1091377
private function dateDiff() : DateInterval
    {
        if (null === $this->dateDiff) {
            $this->dateDiff = $this->from->withTimeAtMidnight()->diff($this->until->withTimeAtMidnight());
        }
        
        return $this->dateDiff;
    }