[前][次][番号順一覧][スレッド一覧]

ruby-changes:26190

From: naruse <ko1@a...>
Date: Fri, 7 Dec 2012 11:55:50 +0900 (JST)
Subject: [ruby-changes:26190] naruse:r38247 (trunk): * time.c (time_mdump): dump timezone string to private instance variable

naruse	2012-12-07 11:55:35 +0900 (Fri, 07 Dec 2012)

  New Revision: 38247

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38247

  Log:
    * time.c (time_mdump): dump timezone string to private instance variable
      on marshaling.
    
    * time.c (time_mload): load timezone string from private instance
      variable named 'zone'.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_time.rb
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 38246)
+++ time.c	(revision 38247)
@@ -29,7 +29,7 @@
 
 #include "timev.h"
 
-static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset;
+static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset, id_zone;
 static ID id_eq, id_ne, id_quo, id_div, id_cmp, id_lshift;
 
 #define NDIV(x,y) (-(-((x)+1)/(y))-1)
@@ -4707,6 +4707,9 @@
 	    off = rb_Integer(div);
 	rb_ivar_set(str, id_offset, off);
     }
+    if (tobj->vtm.zone) {
+	rb_ivar_set(str, id_zone, rb_locale_str_new_cstr(tobj->vtm.zone));
+    }
     return str;
 }
 
@@ -4734,7 +4737,7 @@
     struct vtm vtm;
     int i, gmt;
     long nsec;
-    VALUE submicro, nano_num, nano_den, offset;
+    VALUE submicro, nano_num, nano_den, offset, zone;
     wideval_t timew;
     st_data_t data;
 
@@ -4752,6 +4755,7 @@
     get_attr(nano_den, {});
     get_attr(submicro, {});
     get_attr(offset, validate_utc_offset(offset));
+    get_attr(zone, {});
 #undef get_attr
 
     rb_copy_generic_ivar(time, str);
@@ -4835,6 +4839,9 @@
 	time_set_utc_offset(time, offset);
 	time_fixoff(time);
     }
+    if (!NIL_P(zone)) {
+	tobj->vtm.zone = StringValueCStr(zone);
+    }
 
     return time;
 }
@@ -4955,6 +4962,7 @@
     id_nano_num = rb_intern("nano_num");
     id_nano_den = rb_intern("nano_den");
     id_offset = rb_intern("offset");
+    id_zone = rb_intern("zone");
 
     rb_cTime = rb_define_class("Time", rb_cObject);
     rb_include_module(rb_cTime, rb_mComparable);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38246)
+++ ChangeLog	(revision 38247)
@@ -1,3 +1,11 @@
+Fri Dec  7 09:47:35 2012  NARUSE, Yui  <naruse@r...>
+
+	* time.c (time_mdump): dump timezone string to private instance variable
+	  on marshaling.
+
+	* time.c (time_mload): load timezone string from private instance
+	  variable named 'zone'.
+
 Fri Dec  7 01:15:07 2012  Naohisa Goto  <ngotogenome@g...>
 
 	* ext/fiddle/lib/fiddle/function.rb (Fiddle::Function#name): new
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 38246)
+++ test/ruby/test_time.rb	(revision 38247)
@@ -290,6 +290,21 @@
     assert_equal(29700, t2.utc_offset, bug)
   end
 
+  def test_marshal_zone
+    orig_zone = ENV['TZ']
+
+    t = Time.utc(2013, 2, 24)
+    assert_equal('UTC', t.zone)
+    assert_equal('UTC', Marshal.load(Marshal.dump(t)).zone)
+
+    ENV['TZ'] = 'Asia/Tokyo'
+    t = Time.local(2013, 2, 24)
+    assert_equal('JST', Time.local(2013, 2, 24).zone)
+    assert_equal('JST', Marshal.load(Marshal.dump(t)).zone)
+  ensure
+    ENV['TZ'] = orig_zone
+  end
+
   def test_marshal_to_s
     t1 = Time.new(2011,11,8, 0,42,25, 9*3600)
     t2 = Time.at(Marshal.load(Marshal.dump(t1)))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]