为什么 zone.utc_offset 和 zone.now.utc_offset 之间存在差异?

Why the discrepancy between zone.utc_offset and zone.now.utc_offset?

在 rails 控制台中:

> ActiveSupport::TimeZone['Samoa'].utc_offset
=> -39600
> ActiveSupport::TimeZone['Samoa'].now.utc_offset
=> 50400

我希望看到基于 DST 的差异,也许是一个小时。 为什么这里有巨大的差异?


更新: Samoa 是唯一具有此行为的时区。很容易找到:

ActiveSupport::TimeZone
  .all
  .select{|tz| (tz.now.utc_offset - tz.utc_offset).abs/(3600) > 1}

萨摩亚时区于 2011 年 12 月 29 日跨过国际日期变更线。 https://en.wikipedia.org/wiki/Samoa_Time_Zone

因此 zone.utc_offset 值适用于 2011 年 12 月 29 日之前的值,此后的任何时间 utc_offset 都会适当调整。

> ActiveSupport::TimeZone['Samoa'].parse('2011-01-01').utc_offset
-36000
> ActiveSupport::TimeZone['Samoa'].parse('2015-01-01').utc_offset
50400