src/Carbon/CarbonInterval.php
public static function make($var)
    {
        if ($var instanceof DateInterval) {
            return static::instance($var);
        }

        if (!is_string($var)) {
            return null;
        }

        $var = trim($var);

        if (preg_match('/^P[T0-9]/', $var)) {
            return new static($var);
        }

        if (preg_match('/^(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+$/i', $var)) {
            return static::fromString($var);
        }

        /** @var static $interval */
        $interval = static::createFromDateString($var);

        return $interval->isEmpty() ? null : $interval;
    }
public static function make($var)
    {
        if ($var instanceof DateInterval) {
            return static::instance($var);
        }

        if (!is_string($var)) {
            return null;
        }

        $var = trim($var);

        if (preg_match('/^P[T0-9]/', $var)) {
            return new static($var);
        }

        if (preg_match('/^(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+$/i', $var)) {
            return static::fromString($var);
        }

        /** @var static $interval */
        $interval = static::createFromDateString($var);

        return $interval->isEmpty() ? null : $interval;
    }
public static function make ( $ var ) { if ( $ var instanceof DateInterval ) { return static :: instance ( $ var ) ; } if ( ! is_string ( $ var ) ) { return null ; } $ var = trim ( $ var ) ; if ( preg_match ( '/^P[T0-9]/' , $ var ) ) { return new static ( $ var ) ; } if ( preg_match ( '/^(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+$/i' , $ var ) ) { return static :: fromString ( $ var ) ; } /** @var static $interval */ $ interval = static :: createFromDateString ( $ var ) ; return $ interval -> isEmpty ( ) ? null : $ interval ; }
Make a CarbonInterval instance from given variable if possible.

Always return a new instance. Parse only strings and only these likely to be intervals (skip dates
and recurrences). Throw an exception for invalid format, but otherwise return null.

@param mixed $var

@return static|null
Make a CarbonInterval instance from given variable if possible .