Robert Klemme
4/10/2007 2:21:00 PM
On 10.04.2007 16:03, siemenbaader@gmail.com wrote:
> Hi,
>
> I stumbled across some odd behavior when using Time.parse. Apparently
> <=> fails on Time objects generated by Time.parse when the compared
> objects are equal. The parsed object appears smaller to <=>.
>
>> VERSION
> => "1.8.4"
>
> require 'time'
> => true
>> t = Time.now
> => Tue Apr 10 15:42:40 CEST 2007
>> tt = t.dup
> => Tue Apr 10 15:42:40 CEST 2007
>> t == tt
> => true
>> tt =Time.parse(t.to_s)
> => Tue Apr 10 15:42:40 CEST 2007
>> t == tt
> => false
>> tt < t
> => true
>> t.to_s
> => "Tue Apr 10 15:42:40 CEST 2007"
>> t == Time.parse("Tue Apr 10 15:42:40 CEST 2007")
> => false
>> t > Time.parse("Tue Apr 10 15:42:40 CEST 2007")
> => true
>> t > Time.parse("Tue Apr 10 15:42:41 CEST 2007")
> => false
>> t < Time.parse("Tue Apr 10 15:42:41 CEST 2007")
> => true
>> t > Time.parse("Tue Apr 10 15:42:39 CEST 2007")
> => true
>
> As Time#inspect is overridden i don't know how to examine if there are
> any differences between the objects created with parse and dup
> respectively...
>
> Is this known? Is it a bug or do I misunderstand something?
This is not a bug. Time.parse can only parse what it gets to see:
>> require 'time'
=> true
>> t=Time.now
=> Tue Apr 10 16:19:27 +0200 2007
>> t.to_s
=> "Tue Apr 10 16:19:27 +0200 2007"
>> tt=Time.parse(t.to_s)
=> Tue Apr 10 16:19:27 +0200 2007
>> t.to_s
=> "Tue Apr 10 16:19:27 +0200 2007"
>> tt.to_s
=> "Tue Apr 10 16:19:27 +0200 2007"
>> tt - t
=> -0.125357
>> t.to_f
=> 1176214767.12536
>> tt.to_f
=> 1176214767.0
Kind regards
robert