From: "dafiku (dafi harisy)" Date: 2012-10-23T14:31:27+09:00 Subject: [ruby-dev:46249] [Backport93 - Backport #5586] Time.at(Marshal.load(Marshal.dump(Time.now))).to_s raise TypeError Issue #5586 has been updated by dafiku (dafi harisy). Everlastingly, an issue with the intention of I am passionate in this vicinity. I be inflicted with looked for in rank of this feature for the last numerous hours. Your locate is greatly valued. http://www.yourhousecontents.com/ http://www.electroscanogram.com/ http://www.videophototravel.info/ http://www.supershinelaundry.com/ http://www.ywor.info/ http://www.bicity.info/ http://www.ubidyne.info/ ---------------------------------------- Backport #5586: Time.at(Marshal.load(Marshal.dump(Time.now))).to_s raise TypeError https://bugs.ruby-lang.org/issues/5586#change-31322 Author: nagachika (Tomoyuki Chikanaga) Status: Closed Priority: Normal Assignee: Category: Target version: 以下のコードが TypeError を発生させます。なお 1.9.2-p312 でも発生しました。 Time.at(Marshal.load(Marshal.dump(Time.now))).to_s # => TypeError: false can't be coerced into Fixnum Time オブジェクトを Marshal.dump -> load すると TIME_SET_FIXOFF() で struct time_object の gmt と vtm.utc_offset がセットされるのですが それを Time.at に渡すと gmt だけコピーされて vtm.utc_offset が (VALUE)0 = Qfalse のままだからのようです。 どこが根本的な原因なのかよくわかりませんが、以下のパッチで例外はおきなくなりました。 るりまの Time.at(time) のページ( http://rurema.clear-code.com/1.9.3/method/Time/s/at.html )を見ると 「生成された Time オブジェクトのタイムゾーンは地方時となります。」とあるので TIME_GMT_COPY() 自体が 不要なのかもしれないと思いますがどうでしょう。 diff --git a/time.c b/time.c index 3e50c7c..96b717b 100644 --- a/time.c +++ b/time.c @@ -1820,7 +1820,10 @@ struct time_object { (tobj)->vtm.utc_offset = (off), \ (tobj)->vtm.zone = NULL) -#define TIME_COPY_GMT(tobj1, tobj2) ((tobj1)->gmt = (tobj2)->gmt) +#define TIME_COPY_GMT(tobj1, tobj2) \ + ((tobj1)->gmt = (tobj2)->gmt, \ + (tobj1)->vtm.utc_offset = (tobj2)->vtm.utc_offset, \ + (tobj1)->vtm.zone = (tobj2)->vtm.zone) static VALUE time_get_tm(VALUE, struct time_object *); #define MAKE_TM(time, tobj) \ -- http://bugs.ruby-lang.org/