Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fj
Created October 31, 2014 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fj/d29795586fccc744bdf5 to your computer and use it in GitHub Desktop.
Save fj/d29795586fccc744bdf5 to your computer and use it in GitHub Desktop.
perplexing round-trip Time instance behavior
t1 = Time.now
# => 2014-10-31 13:48:12 -0400
t2 = Time.at(t1.to_i)
# => 2014-10-31 13:48:12 -0400
t1.to_a
# => [12, 48, 13, 31, 10, 2014, 5, 304, true, "EDT"]
t2.to_a
# => [12, 48, 13, 31, 10, 2014, 5, 304, true, "EDT"]
t1.to_a == t2.to_a
# => true
t1 == t2
# => false # !!!!!
@fj
Copy link
Author

fj commented Oct 31, 2014

This happens because Time is tracking subsecond precision, but that's not reflected in the array or in any representation of its state:

t1.subsec.to_f
# => 0.349962996

t2.subsec.to_f
# => 0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment