The time resolution is OS dependent. However, on Unix, the resolution is 
down to seconds. If you need to compare time, it's best to do so by first 
converting them to epoch time (seconds since 1/1/1970).

----- Original Message ----- 
From: "Logan Capaldo" <logancapaldo / gmail.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Sunday, June 11, 2006 3:26 PM
Subject: Re: Comparing times?


>
> On Jun 9, 2006, at 8:10 PM, Eric Armstrong wrote:
>
>> This is driving me crazy. I know I
>> saw a way to do an "almost" comparison,
>> where "x == y +/- some delta". But I'm
>> hanged if I can find it. I've looked
>> everywhere...
>>
>> On a related subject, when Ruby gives me
>> a File time, is it to the nearest second,
>> millisecond, or what, or is it O/S dependent?
>>
>> The goal, of course, is to compare times
>> on two files to see if they are no more
>> than a second apart...
>>
>>
>>
>
> (t1.to_f - t2.to_f).abs < 1.0
>
> #tv_sec will give it to you in integer seconds (same as #to_i)
>
> #tv_usec will give you the fractional number of microseconds (stuff  after 
> the decimal point)
>
> t1.tv_sec * 10**6 + t1.tv_usec should be the time in microseconds. 
> (Divide it by 10.0**6 and you  should get the the same thing as #to_f)
>
>
>
>
>
>
>