From: Logan Capaldo Date: 2006-06-12T04:26:08+09:00 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)