Get timezone offset in hours

@param  string $origin_tz
@param  string $format
@return int
337916
public function getTimezoneHourOffset($origin_tz = 'UTC', $format = 'h') {
        $remote_tz = 'UTC';
        if ($origin_tz === 'UTC') {
            return 0 . 'h';
        }
        $origin_dtz = new \DateTimeZone($origin_tz);
        $remote_dtz = new \DateTimeZone($remote_tz);
        $origin_dt = new \DateTime("now", $origin_dtz);
        $remote_dt = new \DateTime("now", $remote_dtz);

        $offset =  $remote_dtz->getOffset($remote_dt) - $origin_dtz->getOffset($origin_dt);
        return $offset / 3600 . $format;
    }
491836
public function getCreatedTime($format = "")
    {
        $time = $this->created_time;
        if (!empty($format)) {
            $timestamp = strtotime($time);
            $time      = date($format, $timestamp);
        }

        return $time;
    }
982990
public static function get_localised_timezone($tz) {
        if ($tz == 99) {
            $tz = self::get_server_timezone();
            $tz = self::get_localised_timezone($tz);
            return get_string('timezoneserver', 'core_admin', $tz);
        }

        if (get_string_manager()->string_exists(strtolower($tz), 'core_timezones')) {
            $tz = get_string(strtolower($tz), 'core_timezones');
        } else if ($tz === 'GMT' or $tz === 'Etc/GMT' or $tz === 'Etc/UTC') {
            $tz = 'UTC';
        } else if (preg_match('|^Etc/GMT([+-])([0-9]+)$|', $tz, $matches)) {
            $sign = $matches[1] === '+' ? '-' : '+';
            $tz = 'UTC' . $sign . $matches[2];
        }

        return $tz;
    }
144763
function (tp_inst, date) {
		if (tp_inst && tp_inst.timezone_select) {
			var now = date || new Date();
			tp_inst.timezone_select.val(-now.getTimezoneOffset());
		}
	}
649783
public function getOffsetFromGmt($hours = false)
    {
        return (float) $hours ? ($this->tz->getOffset($this) / 3600) : $this->tz->getOffset($this);
    }
188076
def get_offset():
    '''
    
    '''
    # http://craigglennie.com/programming/python/2013/07/21/working-with-timezones-using-Python-and-pytz-localize-vs-normalize/
    tz_object = pytz.timezone(get_zone())
    utc_time = pytz.utc.localize(datetime.utcnow())
    loc_time = utc_time.astimezone(tz_object)
    norm_time = tz_object.normalize(loc_time)
    return norm_time.strftime('%z')
657875
public function format($format, $timezone)
    {
        $date = clone $this->date;
        $date->setTimezone(new DateTimeZone($timezone));
        return $date->format($format);
    }
282389
def fixed_timezone(offset):  # type: (int) -> _FixedTimezone
    
    if offset in _tz_cache:
        return _tz_cache[offset]

    tz = _FixedTimezone(offset)
    _tz_cache[offset] = tz

    return tz
180933
public function format($format = 'local', $timezone = null)
	{
		// custom format pattern lookup
		if (array_key_exists($format, static::$patterns))
		{
			$format = static::$patterns[$format];
		}

		// save the objects timezone
		$orginalTimezone = $this->datetime->getTimezone();

		// default GMT offset
		$offset = 0;

		// want to output in the application default timezone?
		if ($timezone === true)
		{
			$timezone = static::defaultTimezone();
		}

		// output timezone specified?
		elseif ($timezone)
		{
			if ( ! $timezone instanceOf DateTimeZone)
			{
				$this->datetime->setTimezone($timezone = new DateTimeZone($timezone));
			}
		}

		// output in the current timezone
		else
		{
			$timezone = $orginalTimezone;
		}


		// strftime will always do UTC to local time, and
		// strptime() does timezones but no daylight savings,
		// so we might need a correction here

		// offsets are to UTC, so first, UTC -> given timezone, second, UTC -> current object timezone
		$testdate1 = new DateTime('@'.$this->datetime->getTimestamp(), $orginalTimezone);
		$testdate2 = new DateTime('@'.$this->datetime->getTimestamp(), $timezone);

		// offset is the delta between both
		$offset = $timezone->getOffset($testdate1) - $orginalTimezone->getOffset($testdate2);

		// Create output
		if (strpos($format, '%') === false)
		{
			$result = $this->datetime->format($format);
		}
		else
		{
			$result = strftime($format, $this->datetime->getTimestamp() + $offset);
			if (static::$encoding)
			{
				$result = static::$encoding == 'UTF8' ? utf8_encode($result) : iconv('ISO8859-1', static::$encoding, $result);
			}
		}

		// restore the timezone if needed
		if ($timezone !== null)
		{
			$this->datetime->setTimezone($orginalTimezone);
		}

		return $result;
	}
13258
public function getOffsetDates($format, $interval = 30)
    {
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string')
            //argument 2 must be an integer
            ->test(2, 'int');

        $dates = array();
        $interval *= 60;

        for ($i=-12*3600; $i <= (12*3600); $i+=$interval) {
            $time = $this->time + $i;
            $dates[$i] = date($format, $time);
        }

        return $dates;
    }
737599
protected static function getTimezoneObject($tz)
    {
        // If the time zone object is not set, attempt to build it.
        if (!($tz instanceof \DateTimeZone)) {
            if ($tz === null) {
                $tz = static::useServerDefaultTimezone() ? self::$stz : self::$gmt;
            } elseif (is_string($tz)) {
                $tz = new \DateTimeZone($tz);
            } elseif ($tz === static::TZ_LOCALE) {
                $config = Ioc::getConfig();
                $tz     = $config->get('system.timezone');
                $tz     = new \DateTimeZone($tz);
            }
        }

        return $tz;
    }
1045858
public function utcOffset(int $offset = null)
    {
        if (func_num_args() < 1) {
            return $this->offsetMinutes;
        }

        return $this->setTimezone(static::safeCreateDateTimeZone($offset / static::MINUTES_PER_HOUR));
    }
1066669
def _get_tz(tz):
    
    zone = timezones.get_timezone(tz)
    if zone is None:
        zone = tz.utcoffset().total_seconds()
    return zone
1205965
public function format_local($format) {
        // Configure the timezone to account for timezone and/or daylight savings time
        $timezone = new DateTimeZone(date_default_timezone_get());
        $this->setTimezone($timezone);

        $timestamp = $this->getTimestamp();
        return strftime($format, $timestamp);
    }
682083
public void setTimeZone(TimeZone tz)
    {
        setTzFormatString(tz);        
        if( _locale != null ) 
        {
            _tzFormat=new SimpleDateFormat(_tzFormatString,_locale);
            _minFormat=new SimpleDateFormat(_minFormatString,_locale);
        }
        else if( _dfs != null ) 
        {
            _tzFormat=new SimpleDateFormat(_tzFormatString,_dfs);
            _minFormat=new SimpleDateFormat(_minFormatString,_dfs);
        }
        else 
        {
            _tzFormat=new SimpleDateFormat(_tzFormatString);
            _minFormat=new SimpleDateFormat(_minFormatString);
        }
        _tzFormat.setTimeZone(tz);
        _minFormat.setTimeZone(tz);
        _lastSeconds=-1;
        _lastMinutes=-1;        
    }
520640
def current_offset(local_tz=None):
    
    if local_tz is None:
        local_tz = DEFAULT_LOCAL_TZ
    dt = local_tz.localize(datetime.now())
    return dt.utcoffset()
549054
def _tz_offset_string(offset):
        """"""

        s = ""
        io = int(offset)
        if io == 0:
            s += "Z"
        else:
            if -1440 < io < 1440:
                ho = abs(io) / 60
                mo = abs(io) % 60

                s += "%c%02u" % ("+" if io > 0 else "-", ho)
                if mo != 0:
                    s += ":%02u" % mo

            else:
                raise ValueError("Timezone `offset` (%u) out of range "
                                 "-1439 to +1439 minutes" % io)
        return s