Why is there a discrepancy between zone.utc_offset and zone.now.utc_offset?

In the rails console:

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

I expect to see a discrepancy based on DST, perhaps an hour. Why is there a huge difference?


UPDATE: Samoa- This is the only time zone with this behavior. Easy to find:
ActiveSupport::TimeZone
  .all
  .select{|tz| (tz.now.utc_offset - tz.utc_offset).abs/(3600) > 1}
+4
source share
1 answer

Samoa time zone moved through the International Date Line at the end of December 29, 2011. https://en.wikipedia.org/wiki/Samoa_Time_Zone

Thus, the value of zone.utc_offset is for values ​​until December 29, 2011, and at any time after that utc_offset is configured accordingly.

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

Source: https://habr.com/ru/post/1620469/


All Articles