src/DateFormatter.php
public static function safeCreateDateTimeZone($timezone)
    {
        if ($timezone === null) {
            // Don't return null...
            return new DateTimeZone(date_default_timezone_get());
        }

        if ($timezone instanceof DateTimeZone) {
            return $timezone;
        }

        /** @noinspection PhpUsageOfSilenceOperatorInspection */
        $tz = @timezone_open((string) $timezone);

        if ($tz === false) {
            throw new Exception\InvalidArgumentException(
                sprintf(
                    'Unknown or bad timezone (%s)', is_scalar($timezone) ? $timezone : gettype($timezone)
                )
            );
        }

        return $tz;
    }
public static function safeCreateDateTimeZone($timezone)
    {
        if ($timezone === null) {
            // Don't return null...
            return new DateTimeZone(date_default_timezone_get());
        }

        if ($timezone instanceof DateTimeZone) {
            return $timezone;
        }

        /** @noinspection PhpUsageOfSilenceOperatorInspection */
        $tz = @timezone_open((string) $timezone);

        if ($tz === false) {
            throw new Exception\InvalidArgumentException(
                sprintf(
                    'Unknown or bad timezone (%s)', is_scalar($timezone) ? $timezone : gettype($timezone)
                )
            );
        }

        return $tz;
    }
public static function safeCreateDateTimeZone ( $ timezone ) { if ( $ timezone === null ) { // Don't return null... return new DateTimeZone ( date_default_timezone_get ( ) ) ; } if ( $ timezone instanceof DateTimeZone ) { return $ timezone ; } /** @noinspection PhpUsageOfSilenceOperatorInspection */ $ tz = @ timezone_open ( ( string ) $ timezone ) ; if ( $ tz === false ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Unknown or bad timezone (%s)' , is_scalar ( $ timezone ) ? $ timezone : gettype ( $ timezone ) ) ) ; } return $ tz ; }
Creates a DateTimeZone from a string or a DateTimeZone.

@link  \Carbon\Carbon::safeCreateDateTimeZone($object);

@param DateTimeZone|string|null $timezone

@return DateTimeZone
@throws \Xloit\DateTime\Exception\InvalidArgumentException
Creates a DateTimeZone from a string or a DateTimeZone .