diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-21 23:53:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-21 23:53:39 +0000 |
commit | ff31b35f6a66f3c1548e3356d506ff65a574be7f () | |
tree | a8992b8f05ffedcd7c81bf5365e734779b44bdc6 | |
parent | c657e57343133511877beef116386d4c7d324d76 (diff) |
test_time_tz.rb: refactor dummy TZ tests and add another timezone
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_time_tz.rb | 75 |
1 files changed, 38 insertions, 37 deletions
@@ -508,76 +508,77 @@ End end module TestTimeTZ::WithTZ - def tz - @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]) 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) 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) 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]) 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) assert_equal(t.utc_offset, (t2+1).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 |