Why does Date.tomorrow> Time.now return false in Ruby on Rails?

See the result of the RCR console:

[1] pry(main)> Date.tomorrow > Time.now
=> false
[2] pry(main)> Date.tomorrow.to_time > Time.now
=> true
[3] pry(main)> Date.tomorrow
=> Tue, 07 Oct 2014
[4] pry(main)> Time.now
=> 2014-10-06 22:52:40 -0400

Added timestamp result so you know the approximate values.

+4
source share
1 answer

Because Date.tomorrowtomorrow and Time.nowat UTC also tomorrow.

You will notice that you are doing this in 10:52pm(for example, EST)
but actually 2:52am tomorrow (given the difference -0400)

Thus, as tomorrow there will be no more tomorrow, this is a lie.

If you changed it to >=, it may pass.

As you already found, a workaround is to use the key on .to_time

+8
source

All Articles