diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-12 11:40:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-12 11:40:37 +0000 |
commit | f2b6ae1a3c790b8079593b152d9b363e678916c7 (patch) | |
tree | 1df706665959ba4d9238cafba95098ee228fdc2e /test/date | |
parent | ab1098336d02ccb568545b520f96f8511cbff9a0 (diff) | |
download | ruby-f2b6ae1a3c790b8079593b152d9b363e678916c7.tar.gz |
date_core.c: preserve timezone
* ext/date/date_core.c (time_to_time): should preserve timezone
info. [ruby-core:74889] [Bug #12271]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/date')
-rw-r--r-- | test/date/test_date_conv.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb index 0d6c456163..3729476314 100644 --- a/test/date/test_date_conv.rb +++ b/test/date/test_date_conv.rb @@ -3,6 +3,15 @@ require 'test/unit' 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::TestCase 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 |