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 3 years have passed since last update.

RubyでDateとTimeを誤って比較した際、DateはUTCの0時になってTimeと比較する

1
Posted at

ちゃんと意識できていれば踏まないかと思いますが、念の為備忘で書いておきます。

Rails 6.1.3.1
ruby 3.0.0

$ date = Date.current
=> Fri, 23 Jul 2021

$ time = Time.zone.local(2021, 7, 23, 8. 59)
=> Fri, 23 Jul 2021 08:59:00.000000000 JST +09:00

$ date < time
=> false

$ time = Time.zone.local(2021, 7, 23, 9. 1)
=> Fri, 23 Jul 2021 09:01:00.000000000 JST +09:00

$ date < time
=> true

上記の通り、dateがUTCの0時(JSTの9時)になって、timeと比較しているのが分かります。
単純にdateとtimeを意識していれば起こり得ないですが、バグが起きた時の原因調査として残しておきます。

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?