aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-09 06:56:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-09 06:56:38 +0000
commitbda84d49264222ef8c0976bbf1f4d98a56c08f0a (patch)
tree1479cc99453b9013a79cc1191ea32e6a445b189b /test
parent8c600abd217efdd39618c18b519bd0353e95e902 (diff)
downloadruby-bda84d49264222ef8c0976bbf1f4d98a56c08f0a.tar.gz
Add tests for another timezone
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_time_tz.rb59
1 files changed, 45 insertions, 14 deletions
diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb
index daf75234df..97d8c432e8 100644
--- a/test/ruby/test_time_tz.rb
+++ b/test/ruby/test_time_tz.rb
@@ -507,45 +507,76 @@ End
end
end
-class TestTimeTZ::WithTZ < Test::Unit::TestCase
+module TestTimeTZ::WithTZ
def tz
- @tz ||= TestTimeTZ::TZ.new(tzname, abbr, +9*3600)
- end
-
- def tzname
- "Asia/Tokyo"
- end
-
- def abbr
- "JST"
+ @tz ||= TestTimeTZ::TZ.new(tzname, abbr, utc_offset)
end
def test_new
t = Time.new(2018, 9, 1, 12, 0, 0, tz)
assert_equal([2018, 9, 1, 12, 0, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone])
- assert_equal(Time.utc(2018, 9, 1, 3, 0, 0).to_i, t.to_i)
+ h, m = (-utc_offset / 60).divmod(60)
+ assert_equal(Time.utc(2018, 9, 1, 12+h, m, 0).to_i, t.to_i)
end
def test_getlocal
t = Time.utc(2018, 9, 1, 12, 0, 0).getlocal(tz)
- assert_equal([2018, 9, 1, 21, 0, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone])
+ h, m = (utc_offset / 60).divmod(60)
+ assert_equal([2018, 9, 1, 12+h, m, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone])
assert_equal(Time.utc(2018, 9, 1, 12, 0, 0), t)
end
def test_strftime
t = Time.new(2018, 9, 1, 12, 0, 0, tz)
- assert_equal("+0900 #{abbr}", t.strftime("%z %Z"))
+ h, m = (utc_offset.abs / 60).divmod(60)
+ h = -h if utc_offset < 0
+ assert_equal("%+.2d%.2d %s" % [h, m, abbr], t.strftime("%z %Z"))
end
def test_plus
t = Time.new(2018, 9, 1, 12, 0, 0, tz) + 4000
assert_equal([2018, 9, 1, 13, 6, 40, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone])
- assert_equal(Time.utc(2018, 9, 1, 4, 6, 40), t)
+ m, s = (4000-utc_offset).divmod(60)
+ h, m = m.divmod(60)
+ assert_equal(Time.utc(2018, 9, 1, 12+h, m, s), t)
end
def test_marshal
t = Time.new(2018, 9, 1, 12, 0, 0, tz)
t2 = Marshal.load(Marshal.dump(t))
assert_equal(t, t2)
+ assert_equal(t.utc_offset, t2.utc_offset)
+ end
+end
+
+class TestTimeTZ::JST < Test::Unit::TestCase
+ include TestTimeTZ::WithTZ
+
+ def tzname
+ "Asia/Tokyo"
+ end
+
+ def abbr
+ "JST"
+ end
+
+ def utc_offset
+ +9*3600
+ end
+end
+
+class TestTimeTZ::EDT < Test::Unit::TestCase
+ include TestTimeTZ::WithTZ
+
+ def tzname
+ "America/New_York"
+ end
+
+ def abbr
+ "EDT"
+ end
+
+ def utc_offset
+ -4*3600
end
end