diff options
Diffstat (limited to 'spec/ruby')
-rw-r--r-- | spec/ruby/core/time/getlocal_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/time/new_spec.rb | 13 |
2 files changed, 29 insertions, 0 deletions
diff --git a/spec/ruby/core/time/getlocal_spec.rb b/spec/ruby/core/time/getlocal_spec.rb index 39374a3816..87a412f41c 100644 --- a/spec/ruby/core/time/getlocal_spec.rb +++ b/spec/ruby/core/time/getlocal_spec.rb @@ -95,4 +95,20 @@ describe "Time#getlocal" do t.getlocal(86400 - 1).utc_offset.should == (86400 - 1) lambda { t.getlocal(86400) }.should raise_error(ArgumentError) end + + ruby_version_is "2.6" do + describe "with a timezone argument" do + it "returns a Time in the timezone" do + zone = mock('timezone') + zone.should_receive(:utc_to_local).and_return(Time.utc(2000, 1, 1, 17, 30, 0)) + t = Time.utc(2000, 1, 1, 12, 0, 0) + tv = t.to_i + t = t.getlocal(zone) + t.to_a[0, 6].should == [0, 30, 17, 1, 1, 2000] + t.utc_offset.should == 19800 + t.to_i.should == tv + t.zone.should == zone + end + end + end end diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index 2bffe839b8..e0218a2572 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -97,3 +97,16 @@ describe "Time.new with a utc_offset argument" do lambda { Time.new(2000, 1, 1, 0, 0, 0, 86400) }.should raise_error(ArgumentError) end end + +ruby_version_is "2.6" do + describe "Time.new with a timezone argument" do + it "returns a Time correspoinding to UTC time returned by local_to_utc" do + zone = mock('timezone') + zone.should_receive(:local_to_utc).and_return(Time::TM.new(2000, 1, 1, 6, 30, 0)) + t = Time.new(2000, 1, 1, 12, 0, 0, zone) + t.to_a[0, 6].should == [0, 0, 12, 1, 1, 2000] + t.utc_offset.should == 19800 + t.zone.should == zone + end + end +end |