ruby-changes:42479
From: nobu <ko1@a...>
Date: Tue, 12 Apr 2016 19:44:00 +0900 (JST)
Subject: [ruby-changes:42479] nobu:r54553 (trunk): date_core.c: preserve timezone
nobu 2016-04-12 20:40:37 +0900 (Tue, 12 Apr 2016) New Revision: 54553 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54553 Log: date_core.c: preserve timezone * ext/date/date_core.c (time_to_time): should preserve timezone info. [ruby-core:74889] [Bug #12271] Modified files: trunk/ChangeLog trunk/ext/date/date_core.c trunk/test/date/test_date_conv.rb Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 54552) +++ ext/date/date_core.c (revision 54553) @@ -8406,12 +8406,12 @@ dt_lite_jisx0301(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L8406 * call-seq: * t.to_time -> time * - * Returns a copy of self as local mode. + * Returns self. */ static VALUE time_to_time(VALUE self) { - return f_getlocal(self); + return self; } /* Index: test/date/test_date_conv.rb =================================================================== --- test/date/test_date_conv.rb (revision 54552) +++ test/date/test_date_conv.rb (revision 54553) @@ -3,6 +3,15 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/date/test_date_conv.rb#L3 require 'date' class TestDateConv < Test::Unit::TestCase + def with_tz(tz) + old = ENV["TZ"] + begin + ENV["TZ"] = tz + yield + ensure + ENV["TZ"] = old + end + end def test_to_class [Time.now, Date.today, DateTime.now].each do |o| @@ -22,6 +31,14 @@ class TestDateConv < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/date/test_date_conv.rb#L31 t2 = t.to_time.utc assert_equal([2004, 9, 19, 1, 2, 3, 456789], [t2.year, t2.mon, t2.mday, t2.hour, t2.min, t2.sec, t2.usec]) + + t = Time.new(2004, 9, 19, 1, 2, 3, '+03:00') + with_tz('Asia/Tokyo') do + t2 = t.to_time + assert_equal([2004, 9, 19, 1, 2, 3], + [t2.year, t2.mon, t2.mday, t2.hour, t2.min, t2.sec]) + assert_equal(3 * 60 * 60, t2.gmt_offset) + end end def test_to_time__from_date Index: ChangeLog =================================================================== --- ChangeLog (revision 54552) +++ ChangeLog (revision 54553) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Apr 12 20:40:35 2016 Kaneko Yuichiro <spiketeika@g...> + + * ext/date/date_core.c (time_to_time): should preserve timezone + info. [ruby-core:74889] [Bug #12271] + Tue Apr 12 11:51:18 2016 Nobuyoshi Nakada <nobu@r...> * compile.c (new_label_body): initialize bit fields, since -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/