gmt_offset()
public
Show source
static VALUE
time_utc_offset(VALUE time)
{
struct time_object *tobj;
GetTimeval(time, tobj);
if (tobj->tm_got == 0) {
time_get_tm(time, tobj->gmt);
}
if (tobj->gmt == 1) {
return INT2FIX(0);
}
else {
return INT2NUM(tobj->tm.tm_gmtoff);
struct tm *u, *l;
time_t t;
long off;
IF_HAVE_GMTIME_R(struct tm result);
l = &tobj->tm;
t = tobj->ts.tv_sec;
u = GMTIME(&t, result);
if (!u)
rb_raise(rb_eArgError, "gmtime error");
if (l->tm_year != u->tm_year)
off = l->tm_year < u->tm_year ? -1 : 1;
else if (l->tm_mon != u->tm_mon)
off = l->tm_mon < u->tm_mon ? -1 : 1;
else if (l->tm_mday != u->tm_mday)
off = l->tm_mday < u->tm_mday ? -1 : 1;
else
off = 0;
off = off * 24 + l->tm_hour - u->tm_hour;
off = off * 60 + l->tm_min - u->tm_min;
off = off * 60 + l->tm_sec - u->tm_sec;
return LONG2FIX(off);
}
}