utc_offset()
public
Show source
/*
* call-seq:
* time.gmt_offset => fixnum
* time.gmtoff => fixnum
* time.utc_offset => fixnum
*
* Returns the offset in seconds between the timezone of <i>time</i>
* and UTC.
*
* t = Time.gm(2000,1,1,20,15,1)
* t.gmt_offset
* l = t.getlocal
* l.gmt_offset
*/
static VALUE
time_utc_offset(time)
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 {
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
return INT2NUM(tobj->tm.tm_gmtoff);
#else
struct tm *u, *l;
time_t t;
long off;
l = &tobj->tm;
t = tobj->tv.tv_sec;
u = gmtime(&t);
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);
#endif
}
}