Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Time#-
(::Time arg0) -> ::Float
(::Numeric arg0) -> ::Time
self - numeric → new_time
self - other_time → float
time.c
View on GitHub ↗
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);
}
When numeric is given, returns a new Time object whose value is the difference of the numeric value of self and numeric:
Example
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:
Example
t - t # => 0.0
Related: Time#+.