zone()
public
Returns the name of the time zone used for
time. As of Ruby 1.8, returns ``UTC'' rather than ``GMT'' for UTC
times.
t = Time.gm(2000, "jan", 1, 20, 15, 1)
t.zone
t = Time.local(2000, "jan", 1, 20, 15, 1)
t.zone
Show source
/*
* call-seq:
* time.zone => string
*
* Returns the name of the time zone used for <i>time</i>. As of Ruby
* 1.8, returns ``UTC'' rather than ``GMT'' for UTC times.
*
* t = Time.gm(2000, "jan", 1, 20, 15, 1)
* t.zone
* t = Time.local(2000, "jan", 1, 20, 15, 1)
* t.zone
*/
static VALUE
time_zone(time)
VALUE time;
{
struct time_object *tobj;
#if !defined(HAVE_TM_ZONE) && (!defined(HAVE_TZNAME) || !defined(HAVE_DAYLIGHT))
char buf[64];
int len;
#endif
GetTimeval(time, tobj);
if (tobj->tm_got == 0) {
time_get_tm(time, tobj->gmt);
}
if (tobj->gmt == 1) {
return rb_str_new2("UTC");
}
#if defined(HAVE_TM_ZONE)
return rb_str_new2(tobj->tm.tm_zone);
#elif defined(HAVE_TZNAME) && defined(HAVE_DAYLIGHT)
return rb_str_new2(tzname[daylight && tobj->tm.tm_isdst]);
#else
len = strftime(buf, 64, "%Z", &tobj->tm);
return rb_str_new(buf, len);
#endif
}