summaryrefslogtreecommitdiff
path: root/spec/ruby/core/time
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-08 02:35:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-08 02:35:31 +0000
commitee58c638b8d10d2ea10faadbc7b34515d2f2e351 (patch)
tree7716f26c1b8415e0e639bf093e339cdabb13c5aa /spec/ruby/core/time
parente0bc5e49ffc1a013705e1e287967139425912974 (diff)
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
Diffstat (limited to 'spec/ruby/core/time')
-rw-r--r--spec/ruby/core/time/getlocal_spec.rb16
-rw-r--r--spec/ruby/core/time/new_spec.rb13
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