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,18 +53,16 @@ class TimezoneDetect
}
if (Platform::isCli() === false && array_key_exists(self::$cookieName, $_COOKIE)) {
$cookieValue = $_COOKIE[self::$cookieName];
list($offset, $dst) = explode(
strpos($cookieValue, ',') === false ? '-' : ',',
$cookieValue
);
$timezoneName = timezone_name_from_abbr('', (int)$offset, (int)$dst);
$matches = array();
if (preg_match('/\A(-?\d+)[\-,](\d+)\z/', $_COOKIE[self::$cookieName], $matches)) {
$offset = $matches[1];
$timezoneName = timezone_name_from_abbr('', (int) $offset, (int) $matches[2]);
self::$success = (bool)$timezoneName;
if (self::$success === true) {
self::$offset = $offset;
self::$timezoneName = $timezoneName;
self::$success = (bool) $timezoneName;
if (self::$success) {
self::$offset = $offset;
self::$timezoneName = $timezoneName;
}
}
}
}