【问题标题】:tzinfo-data + Rails is reporting the wrong timezone offset for irelandtzinfo-data + Rails 报告爱尔兰的时区偏移量错误
【发布时间】:2018-10-18 19:19:28
【问题描述】:

我在尝试检索爱尔兰的时区时看到了一些奇怪的结果。

在 Mac OS X 上(没有 tzinfo-data)

include ActionView::Helpers::FormOptionsHelper
time_zone_options_for_select.split.select { |opt| opt =~ /Dublin/ }

=> ["value=\"Dublin\">(GMT+00:00)", "Dublin</option>"]

然后在 Ubuntu 上我得到:

=> ["value=\"Dublin\">(GMT+01:00)", "Dublin</option>"]

然后,在带有“tzinfo-data”的 Mac OS X 上,我得到:

=> ["value=\"Dublin\">(GMT+01:00)", "Dublin</option>"]

爱尔兰是 GMT+0(偏移不包括 DST,伦敦目前报告 +0 和马德里 +1,但正如我写的那样,它们都使用 +1 和 +2(BST 和 CEST))

为什么我在 Ubuntu 或 tzinfo-data 上获得 GMT+1?

编辑:

好的,我有一些没有导轨的结果 使用tzinfo-data1.2018.4

> require 'tzinfo/data'
> TZInfo::Timezone.get('Europe/Dublin').current_period.utc_offset
=> 0

使用tzinfo-data1.2018.5

> require 'tzinfo/data'
> TZInfo::Timezone.get('Europe/Dublin').current_period.utc_offset
=> 3600

【问题讨论】:

  • 偏移量确实应该包括夏令时。您可以尝试使用,例如使用timecop gem 模拟另一个日期,然后再次查找时区信息。
  • 但我没有看到其他地区的时区偏移量。例如: > time_zone_options_for_select.split.select { |opt| opt =~ /London|Madrid|Paris/ } => ["value=\"London\">(GMT+00:00)", "London", "value=\"Madrid\">( GMT+01:00)", "Madrid", "value=\"Paris\">(GMT+01:00)", "Paris"] 这些地方实际使用的偏移量分别是 +1、+2 和 +2

标签: ruby-on-rails ruby tzinfo


【解决方案1】:

我发现了问题。事实证明,爱尔兰实际上在冬季使用负抵消,而不是在夏季使用正抵消(它是目前世界上唯一这样做的国家)。

最新的 IANA 时区版本 2018f 正确地使用了爱尔兰的负偏移量,而早期(发布的)版本在夏季使用不同的基准时区和正偏移量。

【讨论】:

  • 谢谢。我以为我今天要疯了,因为我在本地的 mac 和 prod 中的 ubuntu 服务器上运行测试之间存在差异。
猜你喜欢
  • 1970-01-01
  • 2012-10-23
  • 1970-01-01
  • 2011-09-02
  • 1970-01-01
  • 1970-01-01
  • 2019-05-25
  • 1970-01-01
  • 2021-11-30
相关资源
最近更新 更多