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:
nobu 2018-11-04 02:02:28 +00:00
Родитель 356a73e7f2
Коммит 125e9ef747
2 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -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