Gareth Adams
3/13/2008 1:23:00 PM
Stefano Bortolotti wrote:
> I have tried this:
>>> t = Time.now
> => Thu Mar 13 12:57:47 +0100 2008
>>> t1 = Time.now + 1.hours
> => Thu Mar 13 13:58:03 +0100 2008
>>> t2 = t1 - t
> => 3615.968256
>>> tot = Time.at(t2)
> => Thu Jan 01 02:00:15 +0100 1970
>
> but I don't know why the difference between t1 e t is 2 hours and not 1
> hour?
a Time object doesn't represent a duration (2 hours) it represents a
point in time (Jan 1st 1970, 2am). There's no standard Ruby object
representing a time duration, but it seems that a Float (number of
seconds) is good enough.
you can always do (num_of_seconds / 1.hour) to give you a fractional
number of hours etc.
Gareth