Method: Time#-

Defined in:
time.c

#-(numeric) ⇒ Time #-(other_time) ⇒ Float

When numeric is given, returns a new Time object whose value is the difference of the numeric value of self and numeric:

t = Time.new(2000) # => 2000-01-01 00:00:00 -0600
t - (60 * 60 * 24) # => 1999-12-31 00:00:00 -0600
t - 0.5            # => 1999-12-31 23:59:59.5 -0600

When other_time is given, returns a Float whose value is the difference of the numeric values of self and other_time in seconds:

t - t # => 0.0

Related: Time#+.

Overloads:



4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
# File 'time.c', line 4499

static VALUE
time_minus(VALUE time1, VALUE time2)
{
    struct time_object *tobj;

    GetTimeval(time1, tobj);
    if (IsTimeval(time2)) {
        struct time_object *tobj2;

        GetTimeval(time2, tobj2);
        return rb_Float(rb_time_unmagnify_to_float(wsub(tobj->timew, tobj2->timew)));
    }
    return time_add(tobj, time1, time2, -1);
}