-(p1)
public
Difference—Returns a new time that
represents the difference between two times, or subtracts the given number
of seconds in numeric from time.
t = Time.now
t2 = t + 2592000
t2 - t
t2 - 2592000
Show source
/*
* call-seq:
* time - other_time => float
* time - numeric => time
*
* Difference---Returns a new time that represents the difference
* between two times, or subtracts the given number of seconds in
* <i>numeric</i> from <i>time</i>.
*
* t = Time.now #=> Wed Apr 09 08:56:03 CDT 2003
* t2 = t + 2592000 #=> Fri May 09 08:56:03 CDT 2003
* t2 - t #=> 2592000.0
* t2 - 2592000 #=> Wed Apr 09 08:56:03 CDT 2003
*/
static VALUE
time_minus(time1, time2)
VALUE time1, time2;
{
struct time_object *tobj;
GetTimeval(time1, tobj);
if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
struct time_object *tobj2;
double f;
GetTimeval(time2, tobj2);
f = (double)tobj->tv.tv_sec - (double)tobj2->tv.tv_sec;
f += ((double)tobj->tv.tv_usec - (double)tobj2->tv.tv_usec)*1e-6;
/* XXX: should check float overflow on 64bit time_t platforms */
return rb_float_new(f);
}
return time_add(tobj, time2, -1);
}