【发布时间】:2021-02-17 18:23:18
【问题描述】:
Rails 版本:6.0.3.4
红宝石版:2.6.6
tzinfo gem ver: 1.2.7
虽然白天切换应该在 11 月 1 日结束,但我的 rails 应用程序不知何故仍在使用 PDT (-7:00),而我预计它会在 11 月 4 日进入 PST (-08:00)。
> Time.now
2020-11-05 02:45:15 +0000
> Time.zone.now
Wed, 04 Nov 2020 19:45:23 PDT -07:00
这是我目前所知道的:
- 操作系统的
/etc/localtime设置为更正格林威治标准时间 -
config.time_zone设置为Pacific Time (US & Canada) -
config.active_record.default_timezone未设置 - Postgres 设置为 UTC
有人知道发生了什么吗?我注意到Time.zone.tzinfo.current_period 有点奇怪(设置为 2007),但不确定它是否相关:
> Time.zone.tzinfo.current_period
#<TZInfo::TimezonePeriod: #<TZInfo::TimezoneTransitionDefinition: #<TZInfo::TimeOrDateTime: 1173607200>,#<TZInfo::TimezoneOffset: -28800,3600,PDT>>,nil>
> Time.zone.tzinfo.current_period.local_start
Sun, 11 Mar 2007 03:00:00 +0000
> Time.zone.tzinfo.current_period.local_end
nil
更新:这里是 zdump 信息,所以看起来操作系统有正确的信息:
> zdump -v /usr/share/zoneinfo/America/Los_Angeles | grep 2020
/usr/share/zoneinfo/America/Los_Angeles Sun Mar 8 09:59:59 2020 UT = Sun Mar 8 01:59:59 2020 PST isdst=0 gmtoff=-28800
/usr/share/zoneinfo/America/Los_Angeles Sun Mar 8 10:00:00 2020 UT = Sun Mar 8 03:00:00 2020 PDT isdst=1 gmtoff=-25200
/usr/share/zoneinfo/America/Los_Angeles Sun Nov 1 08:59:59 2020 UT = Sun Nov 1 01:59:59 2020 PDT isdst=1 gmtoff=-25200
/usr/share/zoneinfo/America/Los_Angeles Sun Nov 1 09:00:00 2020 UT = Sun Nov 1 01:00:00 2020 PST isdst=0 gmtoff=-28800
更多TZInfo:
> TZInfo::DataSource.get
#<TZInfo::ZoneinfoDataSource: /usr/share/zoneinfo>
【问题讨论】:
-
是的,current_period 不正确。
local_start应该是 2020 年 11 月 1 日,local_end 应该是 2021 年 3 月 14 日。 -
2007 年 3 月 11 日恰逢美国最近一次对 DST 进行全国性变更。
-
很高兴知道!刚刚在问题中添加了 zdump 数据
-
TZInfo::DataSource.get说什么?见TZInfo - Data Sources。 -
刚刚更新了 q 以包含它!
标签: ruby-on-rails ruby timezone