diff options
| author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-06 11:31:46 +0000 |
|---|---|---|
| committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-06 11:31:46 +0000 |
| commit | 401168aa138d847009ec98cbd8d4120498691b2a (patch) | |
| tree | 62fbf14ca3774a1c65436e1b226be59abff18c0d /test | |
| parent | ad837e5a1286ea79e563d3fb928695b171badb83 (diff) | |
merge revision(s) 34072,34075,34082:
* ext/date/date_core.c: [ruby-dev:45008].
* ext/date/date_core.c (wholenum): fix the type of the return value.
* ext/date/date_core.c: uses to_integer instead.
* test/date/test_switch_hitter.rb: added a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
| -rw-r--r-- | test/date/test_switch_hitter.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/date/test_switch_hitter.rb b/test/date/test_switch_hitter.rb index 989d939bb2..8431d40a29 100644 --- a/test/date/test_switch_hitter.rb +++ b/test/date/test_switch_hitter.rb @@ -180,6 +180,75 @@ class TestSH < Test::Unit::TestCase [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) end + def test_fractional + d = Date.jd(2451944.0) + assert_equal(2451944, d.jd) + d = Date.jd(Rational(2451944)) + assert_equal(2451944, d.jd) + d = Date.jd(2451944.5) + assert_equal([2451944, 12], [d.jd, d.send('hour')]) + d = Date.jd(Rational('2451944.5')) + assert_equal([2451944, 12], [d.jd, d.send('hour')]) + + d = Date.civil(2001, 2, 3.0) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = Date.civil(2001, 2, Rational(3)) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = Date.civil(2001, 2, 3.5) + assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')]) + d = Date.civil(2001, 2, Rational('3.5')) + assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')]) + + d = Date.ordinal(2001, 2.0) + assert_equal([2001, 2], [d.year, d.yday]) + d = Date.ordinal(2001, Rational(2)) + assert_equal([2001, 2], [d.year, d.yday]) + + d = Date.commercial(2001, 2, 3.0) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + d = Date.commercial(2001, 2, Rational(3)) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + + d = DateTime.jd(2451944.0) + assert_equal(2451944, d.jd) + d = DateTime.jd(Rational(2451944)) + assert_equal(2451944, d.jd) + d = DateTime.jd(2451944.5) + assert_equal([2451944, 12], [d.jd, d.hour]) + d = DateTime.jd(Rational('2451944.5')) + assert_equal([2451944, 12], [d.jd, d.hour]) + + d = DateTime.civil(2001, 2, 3.0) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = DateTime.civil(2001, 2, Rational(3)) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = DateTime.civil(2001, 2, 3.5) + assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.hour]) + d = DateTime.civil(2001, 2, Rational('3.5')) + assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.hour]) + d = DateTime.civil(2001, 2, 3, 4.5) + assert_equal([2001, 2, 3, 4, 30], [d.year, d.mon, d.mday, d.hour, d.min]) + d = DateTime.civil(2001, 2, 3, Rational('4.5')) + assert_equal([2001, 2, 3, 4, 30], [d.year, d.mon, d.mday, d.hour, d.min]) + d = DateTime.civil(2001, 2, 3, 4, 5.5) + assert_equal([2001, 2, 3, 4, 5, 30], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.civil(2001, 2, 3, 4, Rational('5.5')) + assert_equal([2001, 2, 3, 4, 5, 30], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.ordinal(2001, 2.0) + assert_equal([2001, 2], [d.year, d.yday]) + d = DateTime.ordinal(2001, Rational(2)) + assert_equal([2001, 2], [d.year, d.yday]) + + d = DateTime.commercial(2001, 2, 3.0) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + d = DateTime.commercial(2001, 2, Rational(3)) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + + end + def test_canon24oc d = DateTime.jd(2451943,24) assert_equal([2001, 2, 3, 0, 0, 0, 0], |
