diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-11 13:39:12 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-11 13:39:12 +0000 |
commit | 7c269e72efa9e37150831e6d5d37f4f6f5622d20 (patch) | |
tree | 07d1c93064249f938509784910db2f1c8064f75f /test | |
parent | c2f7ed2f243840ff5e3b0e04e06efcf8a3a0cb6a (diff) | |
download | ruby-7c269e72efa9e37150831e6d5d37f4f6f5622d20.tar.gz |
* time.c (time_round): new method Time#round. [ruby-dev:40595]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_time.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index c583b4e873..6ccac25553 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -576,4 +576,37 @@ class TestTime < Test::Unit::TestCase 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 + + def test_round + t = Time.utc(1999,12,31, 23,59,59) + t2 = (t+0.4).round + assert_equal([59,59,23, 31,12,1999, 5,365,false,"UTC"], t2.to_a) + assert_equal(0, t2.subsec) + t2 = (t+0.49).round + assert_equal([59,59,23, 31,12,1999, 5,365,false,"UTC"], t2.to_a) + assert_equal(0, t2.subsec) + t2 = (t+0.5).round + assert_equal([0,0,0, 1,1,2000, 6,1,false,"UTC"], t2.to_a) + assert_equal(0, t2.subsec) + t2 = (t+1.4).round + assert_equal([0,0,0, 1,1,2000, 6,1,false,"UTC"], t2.to_a) + assert_equal(0, t2.subsec) + t2 = (t+1.49).round + assert_equal([0,0,0, 1,1,2000, 6,1,false,"UTC"], t2.to_a) + assert_equal(0, t2.subsec) + t2 = (t+1.5).round + assert_equal([1,0,0, 1,1,2000, 6,1,false,"UTC"], t2.to_a) + assert_equal(0, t2.subsec) + + t2 = (t+0.123456789).round(4) + assert_equal([59,59,23, 31,12,1999, 5,365,false,"UTC"], t2.to_a) + assert_equal(Rational(1235,10000), t2.subsec) + + off = 0.0 + 100.times {|i| + t2 = (t+off).round(1) + assert_equal(Rational(i % 10, 10), t2.subsec) + off += 0.1 + } + end end |