public static function guessFrom($date)
    {
        if ($date instanceof DateTime) {
            return (new static())->setTimestamp($date->getTimestamp())->setTimezone($date->getTimezone());
        }

        if (is_numeric($date)) {
            return (new static())->setTimestamp((int) $date);
        }

        if (is_object($date) && method_exists($date, 'getTimestamp')) {
            return (new static())->setTimestamp($date->getTimestamp());
        }

        if (!Type::isStringLike($date)) {
            $typeName = Type::of($date);
            throw new InvalidArgumentException("No idea how to cast $typeName to DateTime");
        }

        $date = (string) $date;

        if ($dateTime = date_create($date)) {
            return $dateTime;
        }

        throw new InvalidArgumentException("No idea how to cast $date to DateTime");
    }
public static function guessFrom($date)
    {
        if ($date instanceof DateTime) {
            return (new static())->setTimestamp($date->getTimestamp())->setTimezone($date->getTimezone());
        }

        if (is_numeric($date)) {
            return (new static())->setTimestamp((int) $date);
        }

        if (is_object($date) && method_exists($date, 'getTimestamp')) {
            return (new static())->setTimestamp($date->getTimestamp());
        }

        if (!Type::isStringLike($date)) {
            $typeName = Type::of($date);
            throw new InvalidArgumentException("No idea how to cast $typeName to DateTime");
        }

        $date = (string) $date;

        if ($dateTime = date_create($date)) {
            return $dateTime;
        }

        throw new InvalidArgumentException("No idea how to cast $date to DateTime");
    }
public static function guessFrom ( $ date ) { if ( $ date instanceof DateTime ) { return ( new static ( ) ) -> setTimestamp ( $ date -> getTimestamp ( ) ) -> setTimezone ( $ date -> getTimezone ( ) ) ; } if ( is_numeric ( $ date ) ) { return ( new static ( ) ) -> setTimestamp ( ( int ) $ date ) ; } if ( is_object ( $ date ) && method_exists ( $ date , 'getTimestamp' ) ) { return ( new static ( ) ) -> setTimestamp ( $ date -> getTimestamp ( ) ) ; } if ( ! Type :: isStringLike ( $ date ) ) { $ typeName = Type :: of ( $ date ) ; throw new InvalidArgumentException ( "No idea how to cast $typeName to DateTime" ) ; } $ date = ( string ) $ date ; if ( $ dateTime = date_create ( $ date ) ) { return $ dateTime ; } throw new InvalidArgumentException ( "No idea how to cast $date to DateTime" ) ; }
Try to guess the datetime by the passed string.

@param string $date

@return static
Try to guess the datetime by the passed string .