diff options
-rw-r--r-- | spec/ruby/core/time/localtime_spec.rb | 13 | ||||
-rw-r--r-- | test/ruby/test_time_tz.rb | 11 | ||||
-rw-r--r-- | time.c | 3 |
3 files changed, 27 insertions, 0 deletions
diff --git a/spec/ruby/core/time/localtime_spec.rb b/spec/ruby/core/time/localtime_spec.rb index 56c9d37bc8..5592150ca2 100644 --- a/spec/ruby/core/time/localtime_spec.rb +++ b/spec/ruby/core/time/localtime_spec.rb @@ -90,6 +90,19 @@ describe "Time#localtime" do t.utc_offset.should == -18000 end + + it "does nothing if already in a local time zone" do + time = with_timezone("America/New_York") do + break Time.new(2005, 2, 27, 22, 50, 0) + end + zone = time.zone + + with_timezone("Europe/Amsterdam") do + time.localtime + end + + time.zone.should == zone + end end describe "with an argument that responds to #to_str" do diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index b32caff9c5..f14800a1ad 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -105,6 +105,17 @@ class TestTimeTZ < Test::Unit::TestCase assert_equal(expected, real, m) end + def test_localtime_zone + t = with_tz("America/Los_Angeles") { + Time.local(2000, 1, 1) + } + z1 = t.zone + z2 = with_tz(tz="Asia/Singapore") { + t.localtime.zone + } + assert_equal(z2, z1) + end + def test_america_los_angeles with_tz(tz="America/Los_Angeles") { assert_time_constructor(tz, "2007-03-11 03:00:00 -0700", :local, [2007,3,11,2,0,0]) @@ -3405,6 +3405,9 @@ time_localtime(VALUE time) * * t.localtime("+09:00") #=> 2000-01-02 05:15:01 +0900 * t.utc? #=> false + * + * If +utc_offset+ is not given and _time_ is local time, just return + * the receiver. */ static VALUE |