summaryrefslogtreecommitdiff
path: root/test/date/test_switch_hitter.rb
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-20 12:03:42 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-20 12:03:42 +0000
commit5aea2ad18c622cfa5bb53f1d94e058ac7fc41ad3 (patch)
tree240f047149d39689712546b810c35c929fc96d03 /test/date/test_switch_hitter.rb
parent15e6d26049f5637277e2f4da3b43422e5b41a126 (diff)
* 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/trunk@34082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/date/test_switch_hitter.rb')
-rw-r--r--test/date/test_switch_hitter.rb69
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],