- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
今天,我注意到我的脚本将奥尔森时区 ID 转换并显示为城市和 GMT 偏移量,并产生了一些非常奇怪的结果:阿根廷区域引起了我的注意,因为它们显示标准(非 DST)时间偏移量为 ±0000引用 GMT/UTC。
我检查了我的代码,发现逻辑中有一个小错误,但它与差异无关,因此我通过 pecl
将 timezonedb
更新到版本 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 偏移量与 this Wikipedia page 进行比较:
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。
最佳答案
我将在这里举第一个例子:
[60] => Array
(
[ts] => 1236481200
[time] => 2009-03-08T03:00:00+0000
[offset] => -14400
[isdst] =>
[abbr] => WART
)
However, if you check Time&Date the standard offset should be -10800 (3 hours) and not -14400
据我所知,这不是真的;根据this article ,大约在那个时间(2009 年 3 月 3 日),当没有夏令时时,时区更改为 UTC-4,如果有夏令时,时区更改为 UTC-3。不过,文章中提到的日期是 2015 年 3 月 14 日,而不是 3 月 8 日……我不确定是什么导致了这种差异。
关于php - 奥尔森时区偏移错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13203759/
我们希望在我们的网站上将 Windows 时区转换为 OLSON 时区。然而,奥尔森时区的问题在于它们使用大陆来命名而不是国家/地区名称,例如: America/New_York Asia/Kolka
我是一名优秀的程序员,十分优秀!