aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-04 04:23:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-04 04:23:06 +0000
commit95f396fdd8c6bdf3304a934e4a6d624867fd0198 (patch)
tree2d2f2cc88e48b0c54743d55e260585a6e7e53f89
parent76bac5b37c49a9510e5512a9f0d832ccedbbf618 (diff)
downloadruby-95f396fdd8c6bdf3304a934e4a6d624867fd0198.tar.gz
time.c: preserve marshalled timezone
* time.c (time_add): preserve timezone name restored by Marshal. [ruby-core:81892] [Bug #13710] * time.c (time_mload): reset localtime if having timezone. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_time.rb4
-rw-r--r--time.c20
2 files changed, 16 insertions, 8 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 41d4b03553..c92aafc149 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -308,7 +308,9 @@ class TestTime < Test::Unit::TestCase
in_timezone('JST-9') do
t = Time.local(2013, 2, 24)
assert_equal('JST', Time.local(2013, 2, 24).zone)
- assert_equal('JST', Marshal.load(Marshal.dump(t)).zone)
+ t = Marshal.load(Marshal.dump(t))
+ assert_equal('JST', t.zone)
+ assert_equal('JST', (t+1).zone, '[ruby-core:81892] [Bug #13710]')
end
end
diff --git a/time.c b/time.c
index 3e93e02243..2314aca662 100644
--- a/time.c
+++ b/time.c
@@ -3597,9 +3597,9 @@ time_to_s(VALUE time)
}
static VALUE
-time_add(struct time_object *tobj, VALUE offset, int sign)
+time_add(struct time_object *tobj, VALUE torig, VALUE offset, int sign)
{
- VALUE result;
+ VALUE result, zone;
offset = num_exact(offset);
if (sign < 0)
result = time_new_timew(rb_cTime, wsub(tobj->timew, rb_time_magnify(v2w(offset))));
@@ -3614,6 +3614,11 @@ time_add(struct time_object *tobj, VALUE offset, int sign)
GetTimeval(result, tobj);
TIME_SET_FIXOFF(tobj, off);
}
+ if (!tobj->vtm.zone && !NIL_P(zone = rb_attr_get(torig, id_zone))) {
+ tobj->vtm.zone = StringValueCStr(zone);
+ rb_ivar_set(result, id_zone, zone);
+ }
+
return result;
}
@@ -3637,7 +3642,7 @@ time_plus(VALUE time1, VALUE time2)
if (IsTimeval(time2)) {
rb_raise(rb_eTypeError, "time + time?");
}
- return time_add(tobj, time2, 1);
+ return time_add(tobj, time1, time2, 1);
}
/*
@@ -3667,7 +3672,7 @@ time_minus(VALUE time1, VALUE time2)
GetTimeval(time2, tobj2);
return rb_Float(rb_time_unmagnify_to_float(wsub(tobj->timew, tobj2->timew)));
}
- return time_add(tobj, time2, -1);
+ return time_add(tobj, time1, time2, -1);
}
/*
@@ -3770,9 +3775,9 @@ time_round(int argc, VALUE *argv, VALUE time)
den = quov(INT2FIX(1), a);
v = modv(v, den);
if (lt(v, quov(den, INT2FIX(2))))
- return time_add(tobj, v, -1);
+ return time_add(tobj, time, v, -1);
else
- return time_add(tobj, subv(den, v), 1);
+ return time_add(tobj, time, subv(den, v), 1);
}
/*
@@ -4693,7 +4698,8 @@ end_submicro: ;
time_fixoff(time);
}
if (!NIL_P(zone)) {
- zone = rb_str_new_frozen(zone);
+ if (TIME_FIXOFF_P(tobj)) TIME_SET_LOCALTIME(tobj);
+ zone = rb_fstring(zone);
tobj->vtm.zone = StringValueCStr(zone);
rb_ivar_set(time, id_zone, zone);
}