In Ruby 2.1.2, I can successfully compare the result of Time.parse
and Time.utc
for the same time, and it returns the expected true
:
Time.parse("2015-02-09T22:38:43Z") == Time.utc(2015, 2, 9, 22, 38, 43)
=> true
However, this same comparison counterintuitively returns false
when the second value is not an integer:
Time.parse("2015-02-09T22:38:43.1Z") == Time.utc(2015, 2, 9, 22, 38, 43.1)
=> false
This is despite the fact that the second values are still integers and are still equivalent:
Time.parse("2015-02-09T22:38:43.1Z").sec
=> 43
Time.utc(2015, 2, 9, 22, 38, 43.1).sec
=> 43
Time.parse("2015-02-09T22:38:43.1Z").sec == Time.utc(2015, 2, 9, 22, 38, 43.1).sec
=> true
Moreover, the comparison results in true
between successive calls of the same methods:
Time.parse("2015-02-09T22:38:43.1Z") == Time.parse("2015-02-09T22:38:43.1Z")
=> true
Time.utc(2015, 2, 9, 22, 38, 43.1) == Time.utc(2015, 2, 9, 22, 38, 43.1)
=> true
Why is this so? Is this a bug, or am I missing something?