ruby-on-rails - Rails 不会从夏令时过渡
问题描述
Rails 版本:6.0.3.4
Ruby 版本:2.6.6
tzinfo gem 版本:1.2.7
-7:00
尽管白天切换应该在 11 月 1 日结束,但我的 rails 应用程序在我预计它会在 11 月 4 日在 PST ( ) 时以某种方式仍在使用 PDT ( ) -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
设置为更正 GMT 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>
解决方案
这是由于 tzinfo gem 与新的 tz 版本不兼容:https ://github.com/tzinfo/tzinfo/issues/120
2020b 版的“zic”时区编译器已更改为默认使用新的“slim”格式输出 zoneinfo 文件。slim 格式要求 zoneinfo 文件的用户解释规则,而不仅仅是读取转换列表。
TZInfo 目前仅支持读取转换,需要修改才能使用规则。因此,它会在文件的最终转换后的某个点产生错误的偏移量。
问题从2020b
格式开始。运行时默认ruby:2.6-alpine
安装2020c
apk add tzdata
> docker run -it alpine:3.12
/ > apk add tzdata && apk list | grep tzdata
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tzdata (2020c-r0)
Executing busybox-1.31.1-r19.trigger
OK: 9 MiB in 15 packages
tzdata-2020c-r0 x86_64 {tzdata} (Public-Domain) [installed]
tzdata-doc-2020c-r0 x86_64 {tzdata} (Public-Domain)
推荐阅读
- python - 如何使用opencv(python/c++)从图像中去除模糊
- php - Composer 需要 php 版本 7 ->
- istio - 在 Openshift 上安装 Istio
- python - 循环遍历列表,以便为包含该项目因素的每个项目打印新列表
- arrays - Node.js 写入现有的地理位置 JSON 错误
- angular - 填充所有输入后的角度变化变量
- java - Java - 如何在 switch 语句中调用方法?
- c# - 命名空间“System.Web”中不存在类型或命名空间名称“Script”(您是否缺少程序集引用?)
- django - 无法在 django 表单提交时将值插入数据库
- sql - 更新我的触发器以进行多行插入、更新和删除?