mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Refine Timezone class in test-spec
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
356a73e7f2
commit
125e9ef747
2 changed files with 15 additions and 2 deletions
|
@ -9,4 +9,18 @@ module TimeSpecs
|
|||
end
|
||||
end
|
||||
|
||||
Timezone = Struct.new(:name, :abbr, :offset)
|
||||
class Timezone
|
||||
def utc_offset(t = nil)
|
||||
offset
|
||||
end
|
||||
|
||||
def local_to_utc(t)
|
||||
t - utc_offset(t)
|
||||
end
|
||||
|
||||
def utc_to_local(t)
|
||||
t + utc_offset(t)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -117,8 +117,7 @@ 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))
|
||||
zone = TimeSpecs::Timezone.new("Asia/Colombo", "MMT", (5*3600+30*60))
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue