/** * Normalise the timezone name. If timezone not supported * this method falls back to server timezone (if valid) * or default PHP timezone. * * @param int|string|float|DateTimeZone $tz * @return string timezone compatible with PHP */ public static function normalise_timezone($tz) { global $CFG; if ($tz instanceof DateTimeZone) { return $tz->getName(); } self::init_zones(); $tz = (string) $tz; if (isset(self::$goodzones[$tz]) or isset(self::$bczones[$tz])) { return $tz; } $fixed = false; if (isset(self::$badzones[$tz])) { // Convert to known zone. $tz = self::$badzones[$tz]; $fixed = true; } else { if (is_number($tz)) { // Half hour numeric offsets were already tested, try rounding to integers here. $roundedtz = (string) (int) $tz; if (isset(self::$badzones[$roundedtz])) { $tz = self::$badzones[$roundedtz]; $fixed = true; } } } if ($fixed and isset(self::$goodzones[$tz]) or isset(self::$bczones[$tz])) { return $tz; } // Is server timezone usable? if (isset($CFG->timezone) and !is_numeric($CFG->timezone)) { $result = @timezone_open($CFG->timezone); // Hide notices if invalid. if ($result !== false) { return $result->getName(); } } // Bad luck, use the php.ini default or value set in config.php. return self::get_default_php_timezone(); }