-(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
static VALUE
time_minus(VALUE time1, VALUE 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);
if (tobj->ts.tv_sec < tobj2->ts.tv_sec)
f = -(double)(unsigned_time_t)(tobj2->ts.tv_sec - tobj->ts.tv_sec);
else
f = (double)(unsigned_time_t)(tobj->ts.tv_sec - tobj2->ts.tv_sec);
f += ((double)tobj->ts.tv_nsec - (double)tobj2->ts.tv_nsec)*1e-9;
return DBL2NUM(f);
}
return time_add(tobj, time2, -1);
}