summaryrefslogtreecommitdiff
path: root/jni/ruby/test/date/test_date_attr.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/date/test_date_attr.rb
Fresh start
Diffstat (limited to 'jni/ruby/test/date/test_date_attr.rb')
-rw-r--r--jni/ruby/test/date/test_date_attr.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/jni/ruby/test/date/test_date_attr.rb b/jni/ruby/test/date/test_date_attr.rb
new file mode 100644
index 0000000..bc6bec2
--- /dev/null
+++ b/jni/ruby/test/date/test_date_attr.rb
@@ -0,0 +1,103 @@
+require 'test/unit'
+require 'date'
+
+class TestDateAttr < Test::Unit::TestCase
+
+ def test__attr
+ date = Date.new(1965, 5, 23)
+ datetime = DateTime.new(1965, 5, 23, 22, 31, 59)
+
+ [date, datetime].each_with_index do |d, i|
+
+ if i == 0
+ assert_equal('1965-05-23', d.to_s)
+ else
+ assert_equal('1965-05-23T22:31:59+00:00', d.to_s)
+ end
+
+ assert_equal('', d.inspect.gsub!(/./,''))
+ assert_equal('', d.to_s.gsub!(/./,''))
+
+ assert_equal(2438904, d.jd)
+
+ if i == 0
+ assert_equal(0, d.day_fraction)
+ else
+ assert_equal(22.to_r/24 + 31.to_r/1440 + 59.to_r/86400, d.day_fraction)
+ end
+
+ assert_equal(38903, d.mjd)
+ assert_equal(139744, d.ld)
+
+ assert_equal(1965, d.year)
+ assert_equal(143, d.yday)
+ assert_equal(5, d.mon)
+ assert_equal(d.mon, d.month)
+ assert_equal(23, d.mday)
+ assert_equal(d.mday, d.day)
+
+ if i == 0
+ assert_equal(false, d.respond_to?(:hour))
+ assert_equal(false, d.respond_to?(:min))
+ assert_equal(false, d.respond_to?(:sec))
+ assert_equal(false, d.respond_to?(:sec_fraction))
+ assert_equal(false, d.respond_to?(:zone))
+ assert_equal(false, d.respond_to?(:offset))
+ else
+ assert_equal(22, d.hour)
+ assert_equal(31, d.min)
+ assert_equal(59, d.sec)
+ assert_equal(0, d.sec_fraction)
+ assert_equal('+00:00', d.zone)
+ assert_equal(0, d.offset)
+ end
+
+ assert_equal(1965, d.cwyear)
+ assert_equal(20, d.cweek)
+ assert_equal(7, d.cwday)
+
+ assert_equal(0, d.wday)
+ assert_equal(false, d.leap?)
+ assert_equal(false, d.julian?)
+ assert_equal(true, d.gregorian?)
+
+ assert_equal(Date::ITALY, d.start)
+ assert_equal(d.start, d.start)
+ end
+
+ d = DateTime.new(1965, 5, 23, 22, 31, 59) + 1.to_r/(86400*2)
+ assert_equal(1.to_r/2, d.sec_fraction)
+ end
+
+ def test__wday_predicate
+ d = Date.new(2005, 10, 23)
+ assert_equal(true, d.sunday?)
+ assert_equal(false, d.monday?)
+ assert_equal(false, d.tuesday?)
+ assert_equal(false, d.wednesday?)
+ assert_equal(false, d.thursday?)
+ assert_equal(false, d.friday?)
+ assert_equal(false, d.saturday?)
+
+ d = Date.new(2005, 10, 30)
+ 14.times do |i|
+ assert((d + i).__send__(%w(sunday? monday? tuesday? wednesday?
+ thursday? friday? saturday?)[i % 7]))
+ end
+ end
+
+ def test_nth_kday
+ skip unless Date.new.respond_to?(:nth_kday?, true)
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, 1,0))
+ assert_equal(true, Date.new(2001,1,14).__send__(:nth_kday?, 2,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, 3,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, 4,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, 5,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, -1,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, -2,0))
+ assert_equal(true, Date.new(2001,1,14).__send__(:nth_kday?, -3,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, -4,0))
+ assert_equal(false, Date.new(2001,1,14).__send__(:nth_kday?, -5,0))
+ end
+
+end