Comparing time with ActiveSupport

now = Time.zone.now => Wed, 19 Feb 2014 21:30:56 UTC +00:00 Time.zone.at(now.to_i) => Wed, 19 Feb 2014 21:30:56 UTC +00:00 now == Time.zone.at(now.to_i) => false 

How is this possible?

Upd:

 Time.zone.at(now.to_i).to_i == now.to_i => true 
+6
source share
1 answer

Ruby run time to nanoseconds:

 now = Time.zone.now => Wed, 19 Feb 2014 21:30:56 UTC +00:00 Time.zone.at(now.to_f) => Wed, 19 Feb 2014 21:30:56 UTC +00:00 now == Time.zone.at(now.to_f) => false 

But if you compare nanoseconds, you will see that they do not match even when creating a time object using the float value, since the float used to create a new time object is not as accurate as the nanosecond time value:

 now.nsec => 956134961 Time.zone.at(now.to_f).nsec => 956134796 
+3
source

All Articles