Method: Time#getlocal
- Defined in:
- time.c
#getlocal(zone = nil) ⇒ Time
Returns a new Time object representing the value of self converted to a given timezone; if zone is nil, the local timezone is used:
t = Time.utc(2000) # => 2000-01-01 00:00:00 UTC
t.getlocal # => 1999-12-31 18:00:00 -0600
t.getlocal('+12:00') # => 2000-01-01 12:00:00 +1200
For forms of argument zone, see Timezone Specifiers.
4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 |
# File 'time.c', line 4200
static VALUE
time_getlocaltime(int argc, VALUE *argv, VALUE time)
{
VALUE off;
if (rb_check_arity(argc, 0, 1) && !NIL_P(off = argv[0])) {
VALUE zone = off;
if (maybe_tzobj_p(zone)) {
VALUE t = time_dup(time);
if (zone_localtime(off, t)) return t;
}
if (NIL_P(off = utc_offset_arg(off))) {
off = zone;
if (NIL_P(zone = find_timezone(time, off))) invalid_utc_offset(off);
time = time_dup(time);
if (!zone_localtime(zone, time)) invalid_utc_offset(off);
return time;
}
else if (off == UTC_ZONE) {
return time_gmtime(time_dup(time));
}
validate_utc_offset(off);
time = time_dup(time);
time_set_utc_offset(time, off);
return time_fixoff(time);
}
return time_localtime(time_dup(time));
}
|