<=>(p1)
public
Comparison—Compares time with other_time.
t = Time.now
t2 = t + 2592000
t <=> t2
t2 <=> t
t = Time.now
t2 = t + 0.1
t.nsec
t2.nsec
t <=> t2
t2 <=> t
t <=> t
Show source
static VALUE
time_cmp(VALUE time1, VALUE time2)
{
struct time_object *tobj1, *tobj2;
GetTimeval(time1, tobj1);
if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
GetTimeval(time2, tobj2);
if (tobj1->ts.tv_sec == tobj2->ts.tv_sec) {
if (tobj1->ts.tv_nsec == tobj2->ts.tv_nsec) return INT2FIX(0);
if (tobj1->ts.tv_nsec > tobj2->ts.tv_nsec) return INT2FIX(1);
return INT2FIX(-1);
}
if (tobj1->ts.tv_sec > tobj2->ts.tv_sec) return INT2FIX(1);
return INT2FIX(-1);
}
else {
VALUE cmp;
int n;
cmp = rb_funcall(time2, rb_intern("<=>"), 1, time1);
if (NIL_P(cmp)) return Qnil;
n = -rb_cmpint(cmp, time1, time2);
if (n == 0) return INT2FIX(0);
if (n > 0) return INT2FIX(1);
return INT2FIX(-1);
}
}