Karijuana
Karijuana

Reputation: 324

True time comparison returns false

This:

puts send_time
puts DateTime.now.to_time
puts send_time === DateTime.now.to_time

Returns this:

2014-07-29 12:14:00 -0400
2014-07-29 12:14:00 -0400
false

Is this rails bug or am I missing something?

Upvotes: 1

Views: 107

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54882

The puts method calls an implicit .to_s on the code being displayed. This is probably causing the error:

puts send_time.to_s === DateTime.now.to_time.to_s

Should return true

And the following:

puts send_time.to_time == DateTime.now.to_time

Should return true also (only two equals, not three)

Upvotes: 1

Related Questions