From ee58c638b8d10d2ea10faadbc7b34515d2f2e351 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 8 Oct 2018 02:35:31 +0000 Subject: Timezone support by Time [Feature #14850] * strftime.c (rb_strftime): support timezone object by `%z`. * time.c (time_init_1, time_new_timew, time_getlocaltime): accept timezone object as `off`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/time/getlocal_spec.rb | 16 ++++++++++++++++ spec/ruby/core/time/new_spec.rb | 13 +++++++++++++ 2 files changed, 29 insertions(+) (limited to 'spec/ruby') 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 -- cgit v1.2.3