今天我注意到我的脚本将奥尔森时区 ID 转换并显示为城市和 GMT 偏移量产生了一些非常奇怪的结果:阿根廷区域引起了我的注意,因为它们显示的标准(非 DST)时间偏移量为 ±0000 参考 GMT /世界标准时间。
我检查了我的代码,在我的逻辑中发现了一个小错误,但它与差异无关,所以我timezonedb
通过pecl
版本更新2012.8
但它仍然返回错误的偏移量......
以下是一些返回America/Argentina/San_Luis
时区最近 3 次更改的代码:
$timezone = new DateTimeZone('America/Argentina/San_Luis');
$transitions = $timezone->getTransitions();
echo '<pre>';
print_r(array_slice($transitions, -3, null, true));
echo '</pre>';
这是输出:
Array
(
[59] => Array
(
[ts] => 1223784000
[time] => 2008-10-12T04:00:00+0000
[offset] => -10800
[isdst] => 1
[abbr] => WARST
)
[60] => Array
(
[ts] => 1236481200
[time] => 2009-03-08T03:00:00+0000
[offset] => -14400
[isdst] =>
[abbr] => WART
)
[61] => Array
(
[ts] => 1255233600
[time] => 2009-10-11T04:00:00+0000
[offset] => -10800
[isdst] => 1
[abbr] => WARST
)
)
如您所见,索引59
和61
是 DST 偏移量,而索引60
是标准时间偏移量。
但是,如果您检查Time&Date标准偏移量应该是-10800
(3 小时),而不是-14400
:
Standard time zone: UTC/GMT -3 hours
No daylight saving time in 2012
Time zone abbreviation: ART - Argentina Time
事实上,即使abbr
是错误的(应该是ART
从2009-10-10 DST 起停止了)。
这里出了什么问题?我很确定这无关紧要,但如果重要的话,我正在运行 PHP 5.4.6。
PS:我记得读过有关 Olson 数据库的一些法律问题,这可能与此有关吗?
更新:我写了一个小脚本来比较 PHP 非 DST 偏移量和这个维基百科页面:
function getStandardOffset($timezone)
{
$timezone = new DateTimeZone($timezone);
//$hemisphere = (ph()->Value($timezone->getLocation(), 'latitude') >= 0) ? 'north' : 'south';
$transitions = array_reverse(array_slice($timezone->getTransitions(), -3, null, true), true);
foreach ($transitions as $transition)
{
if ($transition['isdst'] == 1)
{
continue;
}
return sprintf('%+03d:%02u', $transition['offset'] / 3600, abs($transition['offset']) % 3600 / 60);
}
return false;
}
$diff = array();
$html = ph()->HTML->DOM(file_get_contents('http://en.wikipedia.org/wiki/List_of_tz_database_time_zones'));
$timezones = DateTimeZone::listIdentifiers();
foreach ($timezones as $timezone)
{
$offset = str_replace('−', '-', ph()->HTML->DOM($html, sprintf('//td/a[contains(text(), "%s")]/../..', $timezone), '0.td.4.a'));
if (strcmp($offset, getStandardOffset($timezone)) !== 0)
{
$diff[$timezone] = array
(
'php' => getStandardOffset($timezone),
'wiki' => $offset,
);
}
}
echo '<pre>';
print_r($diff);
echo '</pre>';
以下时区不同:
Array
(
[America/Argentina/San_Luis] => Array
(
[php] => -04:00
[wiki] => -03:00
)
[Antarctica/Casey] => Array
(
[php] => +08:00
[wiki] => +11:00
)
[Antarctica/Davis] => Array
(
[php] => +07:00
[wiki] => +05:00
)
)
这不是什么大不了的事,但我很好奇为什么会发生这种情况,因为我拥有最新版本的 Olson tzdb。