diff options
Diffstat (limited to 'test/ruby/test_time.rb')
-rw-r--r-- | test/ruby/test_time.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index d7e736de3a..c583b4e873 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -27,6 +27,16 @@ class TestTime < Test::Unit::TestCase assert_equal(Time.utc(2000, 3, 21, 3, 30) + (-3 * 3600), Time.utc(2000, 3, 21, 0, 30)) assert_equal(0, (Time.at(1.1) + 0.9).usec) + + assert((Time.utc(2000, 4, 1) + 24).utc?) + assert(!(Time.local(2000, 4, 1) + 24).utc?) + + t = Time.new(2000, 4, 1, 0, 0, 0, "+01:00") + 24 + assert(!t.utc?) + assert_equal(3600, t.utc_offset) + t = Time.new(2000, 4, 1, 0, 0, 0, "+02:00") + 24 + assert(!t.utc?) + assert_equal(7200, t.utc_offset) end def test_time_subt() @@ -191,6 +201,18 @@ class TestTime < Test::Unit::TestCase assert_marshal_roundtrip(Time.at(0, 0.120)) end + def test_marshal_nsec_191 + # generated by ruby 1.9.1p376 + m = "\x04\bIu:\tTime\r \x80\x11\x80@\xE2\x01\x00\x06:\rsubmicro\"\ax\x90" + t = Marshal.load(m) + assert_equal(Time.at(Rational(123456789, 1000000000)), t, "[ruby-dev:40133]") + end + + def test_marshal_rational + assert_marshal_roundtrip(Time.at(0, Rational(1,3))) + assert_not_match(/Rational/, Marshal.dump(Time.at(0, Rational(1,3)))) + end + def test_marshal_ivar t = Time.at(123456789, 987654.321) t.instance_eval { @var = 135 } @@ -198,6 +220,20 @@ class TestTime < Test::Unit::TestCase assert_marshal_roundtrip(Marshal.load(Marshal.dump(t))) end + def test_marshal_timezone + bug = '[ruby-dev:40063]' + + t1 = Time.gm(2000) + m = Marshal.dump(t1.getlocal("-02:00")) + t2 = Marshal.load(m) + assert_equal(t1, t2) + assert_equal(-7200, t2.utc_offset, bug) + m = Marshal.dump(t1.getlocal("+08:15")) + t2 = Marshal.load(m) + assert_equal(t1, t2) + assert_equal(29700, t2.utc_offset, bug) + end + # Sat Jan 01 00:00:00 UTC 2000 T2000 = Time.at(946684800).gmtime @@ -351,6 +387,26 @@ class TestTime < Test::Unit::TestCase assert_equal(T2000 + 1, T2000.succ) end + def test_plus_type + t0 = Time.utc(2000,1,1) + n0 = t0.to_i + n1 = n0+1 + t1 = Time.at(n1) + assert_equal(t1, t0 + 1) + assert_equal(t1, t0 + 1.0) + assert_equal(t1, t0 + Rational(1,1)) + assert_equal(t1, t0 + SimpleDelegator.new(1)) + assert_equal(t1, t0 + SimpleDelegator.new(1.0)) + assert_equal(t1, t0 + SimpleDelegator.new(Rational(1,1))) + assert_raise(TypeError) { t0 + nil } + assert_raise(TypeError) { t0 + "1" } + assert_raise(TypeError) { t0 + SimpleDelegator.new("1") } + assert_equal(0.5, (t0 + 1.5).subsec) + assert_equal(Rational(1,3), (t0 + Rational(4,3)).subsec) + assert_equal(0.5, (t0 + SimpleDelegator.new(1.5)).subsec) + assert_equal(Rational(1,3), (t0 + SimpleDelegator.new(Rational(4,3))).subsec) + end + def test_readers assert_equal(0, T2000.sec) assert_equal(0, T2000.min) @@ -515,4 +571,9 @@ class TestTime < Test::Unit::TestCase assert_equal(-1, d1 <=> d2) assert_equal(1, d2 <=> d1) end + + def test_to_r + assert_kind_of(Rational, Time.new(2000,1,1,0,0,Rational(4,3)).to_r) + assert_kind_of(Rational, Time.utc(1970).to_r) + end end |