gpt4 book ai didi

ruby-on-rails - Rails 不会从夏令时过渡出来

转载 作者:行者123 更新时间:2023-12-03 23:42:55 25 4
gpt4 key购买 nike

rails 版本:6.0.3.4 ruby 版本:2.6.6tzinfo gem 版本: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设置为更正 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

    The 2020b version of the 'zic' time zone compiler has changed to output zoneinfo files using a new 'slim' format by default. The slim format requires users of the zoneinfo files to interpret rules instead of just reading a list of transitions.

    TZInfo currently only supports reading the transitions and will require modification to use the rules. Consequently, it'll produce the wrong offset at some point after the final transition in the file.


    问题始于 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)

    关于ruby-on-rails - Rails 不会从夏令时过渡出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64690547/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com