TimezoneDetect: support also negative timezone offsets

refs #2716
This commit is contained in:
Alexander A. Klimov 2017-02-08 16:51:19 +01:00
parent 80d3abed9d
commit e5f462c2fa
1 changed files with 9 additions and 11 deletions

View File

@ -53,21 +53,19 @@ class TimezoneDetect
} }
if (Platform::isCli() === false && array_key_exists(self::$cookieName, $_COOKIE)) { if (Platform::isCli() === false && array_key_exists(self::$cookieName, $_COOKIE)) {
$cookieValue = $_COOKIE[self::$cookieName]; $matches = array();
list($offset, $dst) = explode( if (preg_match('/\A(-?\d+)[\-,](\d+)\z/', $_COOKIE[self::$cookieName], $matches)) {
strpos($cookieValue, ',') === false ? '-' : ',', $offset = $matches[1];
$cookieValue $timezoneName = timezone_name_from_abbr('', (int) $offset, (int) $matches[2]);
);
$timezoneName = timezone_name_from_abbr('', (int)$offset, (int)$dst);
self::$success = (bool)$timezoneName; self::$success = (bool) $timezoneName;
if (self::$success) {
if (self::$success === true) {
self::$offset = $offset; self::$offset = $offset;
self::$timezoneName = $timezoneName; self::$timezoneName = $timezoneName;
} }
} }
} }
}
/** /**
* Get offset * Get offset