/** * Returns an int which represents the systems's timezone difference from GMT in seconds * * @package core * @category time * @param float|int|string $tz timezone for which offset is required. * {@link http://docs.moodle.org/dev/Time_API#Timezone} * @return int|bool if found, false is timezone 99 or error */ function get_timezone_offset($tz) { if ($tz == 99) { return false; } if (is_numeric($tz)) { return intval($tz * 60*60); } if (!$tzrecord = get_timezone_record($tz)) { return false; } return intval($tzrecord->gmtoff * 60); }
/** * Returns a float which represents the user's timezone difference from GMT in hours * Checks various settings and picks the most dominant of those which have a value * * @uses $CFG * @uses $USER * @param float $tz If this value is provided and not equal to 99, it will be returned as is and no other settings will be checked * @return int */ function get_user_timezone_offset($tz = 99) { global $USER, $CFG; $tz = get_user_timezone($tz); if (is_float($tz)) { return $tz; } else { $tzrecord = get_timezone_record($tz); if (empty($tzrecord)) { return 99.0; } return (double) $tzrecord->gmtoff / HOURMINS; } }