1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ActiveSupport::TimeZoneを0オフセットでインスタンス化すると1時間ずれる

Posted at

指定したオフセット値(JSTなら9時間)で ActiveSupport::TimeZone を作り、それをもとに ActiveSupport::TimeWithZone インスタンスを作りたい。

jst = ActiveSupport::TimeZone[9]
# => #<ActiveSupport::TimeZone:0x00007fbbe3b034b0 @name="Osaka", @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: Asia/Tokyo>>

jst.now
# => Fri, 21 Jun 2019 21:24:26 JST +09:00

+9は、問題なし。

utc = ActiveSupport::TimeZone[0]
# => #<ActiveSupport::TimeZone:0x00007fbbe3afb030 @name="Casablanca", @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: Africa/Casablanca>>

utc.now
# => Fri, 21 Jun 2019 13:25:48 WEST +01:00

utc.tzinfo.current_period.utc_offset                      
# => 0

ファッ!? +00:00 が期待されるところ +01:00 となっている!?
TZInfoのutc_offsetは0を指しているようだが...

そもそもoffsetだけではtimezoneと言えないのでやろうとしていることが強引な気もするが、それはさておき、どうやるのが正解なのだろうか。


関係ありそうだが、詳しくは読んでない。
https://github.com/tzinfo/tzinfo/issues/98


動作確認環境
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]
activesupport (5.2.1)
tzinfo (1.2.5)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?