<=>(p1)
public
Comparison—Compares time with other_time or with
numeric, which is the number of seconds (possibly fractional)
since epoch.
t = Time.now
t2 = t + 2592000
t <=> t2
t2 <=> t
t <=> t
Show source
/*
* call-seq:
* time <=> other_time => -1, 0, +1
* time <=> numeric => -1, 0, +1
*
* Comparison---Compares <i>time</i> with <i>other_time</i> or with
* <i>numeric</i>, which is the number of seconds (possibly
* fractional) since epoch.
*
* t = Time.now
* t2 = t + 2592000
* t <=> t2
* t2 <=> t
* t <=> t
*/
static VALUE
time_cmp(time1, time2)
VALUE time1, time2;
{
struct time_object *tobj1, *tobj2;
GetTimeval(time1, tobj1);
if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
GetTimeval(time2, tobj2);
if (tobj1->tv.tv_sec == tobj2->tv.tv_sec) {
if (tobj1->tv.tv_usec == tobj2->tv.tv_usec) return INT2FIX(0);
if (tobj1->tv.tv_usec > tobj2->tv.tv_usec) return INT2FIX(1);
return INT2FIX(-1);
}
if (tobj1->tv.tv_sec > tobj2->tv.tv_sec) return INT2FIX(1);
return INT2FIX(-1);
}
return Qnil;
}