From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/test/date/test_date.rb | 150 ++++ jni/ruby/test/date/test_date_arith.rb | 264 +++++++ jni/ruby/test/date/test_date_attr.rb | 103 +++ jni/ruby/test/date/test_date_base.rb | 442 ++++++++++++ jni/ruby/test/date/test_date_compat.rb | 21 + jni/ruby/test/date/test_date_conv.rb | 137 ++++ jni/ruby/test/date/test_date_marshal.rb | 41 ++ jni/ruby/test/date/test_date_new.rb | 271 +++++++ jni/ruby/test/date/test_date_parse.rb | 1124 ++++++++++++++++++++++++++++++ jni/ruby/test/date/test_date_strftime.rb | 422 +++++++++++ jni/ruby/test/date/test_date_strptime.rb | 512 ++++++++++++++ jni/ruby/test/date/test_switch_hitter.rb | 664 ++++++++++++++++++ 12 files changed, 4151 insertions(+) create mode 100644 jni/ruby/test/date/test_date.rb create mode 100644 jni/ruby/test/date/test_date_arith.rb create mode 100644 jni/ruby/test/date/test_date_attr.rb create mode 100644 jni/ruby/test/date/test_date_base.rb create mode 100644 jni/ruby/test/date/test_date_compat.rb create mode 100644 jni/ruby/test/date/test_date_conv.rb create mode 100644 jni/ruby/test/date/test_date_marshal.rb create mode 100644 jni/ruby/test/date/test_date_new.rb create mode 100644 jni/ruby/test/date/test_date_parse.rb create mode 100644 jni/ruby/test/date/test_date_strftime.rb create mode 100644 jni/ruby/test/date/test_date_strptime.rb create mode 100644 jni/ruby/test/date/test_switch_hitter.rb (limited to 'jni/ruby/test/date') diff --git a/jni/ruby/test/date/test_date.rb b/jni/ruby/test/date/test_date.rb new file mode 100644 index 0000000..3d8bf86 --- /dev/null +++ b/jni/ruby/test/date/test_date.rb @@ -0,0 +1,150 @@ +require 'test/unit' +require 'date' + +class DateSub < Date; end +class DateTimeSub < DateTime; end + +class TestDate < Test::Unit::TestCase + + def test__const + assert_nil(Date::MONTHNAMES[0]) + assert_equal('January', Date::MONTHNAMES[1]) + assert_equal(13, Date::MONTHNAMES.size) + assert_equal('Sunday', Date::DAYNAMES[0]) + assert_equal(7, Date::DAYNAMES.size) + + assert_nil(Date::ABBR_MONTHNAMES[0]) + assert_equal('Jan', Date::ABBR_MONTHNAMES[1]) + assert_equal(13, Date::ABBR_MONTHNAMES.size) + assert_equal('Sun', Date::ABBR_DAYNAMES[0]) + assert_equal(7, Date::ABBR_DAYNAMES.size) + + assert(Date::MONTHNAMES.frozen?) + assert(Date::MONTHNAMES[1].frozen?) + assert(Date::DAYNAMES.frozen?) + assert(Date::DAYNAMES[0].frozen?) + + assert(Date::ABBR_MONTHNAMES.frozen?) + assert(Date::ABBR_MONTHNAMES[1].frozen?) + assert(Date::ABBR_DAYNAMES.frozen?) + assert(Date::ABBR_DAYNAMES[0].frozen?) + end + + def test_sub + d = DateSub.new + dt = DateTimeSub.new + + assert_instance_of(DateSub, d) + assert_instance_of(DateTimeSub, dt) + + assert_instance_of(DateSub, DateSub.today) + assert_instance_of(DateTimeSub, DateTimeSub.now) + + assert_equal('-4712-01-01', d.to_s) + assert_equal('-4712-01-01T00:00:00+00:00', dt.to_s) + + d2 = d + 1 + assert_instance_of(DateSub, d2) + d2 = d - 1 + assert_instance_of(DateSub, d2) + d2 = d >> 1 + assert_instance_of(DateSub, d2) + d2 = d << 1 + assert_instance_of(DateSub, d2) + d2 = d.succ + assert_instance_of(DateSub, d2) + d2 = d.next + assert_instance_of(DateSub, d2) + d2 = d.italy + assert_instance_of(DateSub, d2) + d2 = d.england + assert_instance_of(DateSub, d2) + d2 = d.julian + assert_instance_of(DateSub, d2) + d2 = d.gregorian + assert_instance_of(DateSub, d2) + s = Marshal.dump(d) + d2 = Marshal.load(s) + assert_equal(d2, d) + assert_instance_of(DateSub, d2) + + dt2 = dt + 1 + assert_instance_of(DateTimeSub, dt2) + dt2 = dt - 1 + assert_instance_of(DateTimeSub, dt2) + dt2 = dt >> 1 + assert_instance_of(DateTimeSub, dt2) + dt2 = dt << 1 + assert_instance_of(DateTimeSub, dt2) + dt2 = dt.succ + assert_instance_of(DateTimeSub, dt2) + dt2 = dt.next + assert_instance_of(DateTimeSub, dt2) + dt2 = dt.italy + assert_instance_of(DateTimeSub, dt2) + dt2 = dt.england + assert_instance_of(DateTimeSub, dt2) + dt2 = dt.julian + assert_instance_of(DateTimeSub, dt2) + dt2 = dt.gregorian + assert_instance_of(DateTimeSub, dt2) + s = Marshal.dump(dt) + dt2 = Marshal.load(s) + assert_equal(dt2, dt) + assert_instance_of(DateTimeSub, dt2) + end + + def test_eql_p + d = Date.jd(0) + d2 = Date.jd(0) + dt = DateTime.jd(0) + dt2 = DateTime.jd(0) + + assert_equal(d, d2) + assert_not_equal(d, 0) + + assert_equal(dt, dt2) + assert_not_equal(dt, 0) + + assert_equal(d, dt) + assert_equal(d2, dt2) + end + + def test_hash + h = {} + h[Date.new(1999,5,23)] = 0 + h[Date.new(1999,5,24)] = 1 + h[Date.new(1999,5,25)] = 2 + h[Date.new(1999,5,25)] = 9 + assert_equal(3, h.size) + assert_equal(9, h[Date.new(1999,5,25)]) + assert_equal(9, h[DateTime.new(1999,5,25)]) + + h = {} + h[DateTime.new(1999,5,23)] = 0 + h[DateTime.new(1999,5,24)] = 1 + h[DateTime.new(1999,5,25)] = 2 + h[DateTime.new(1999,5,25)] = 9 + assert_equal(3, h.size) + assert_equal(9, h[Date.new(1999,5,25)]) + assert_equal(9, h[DateTime.new(1999,5,25)]) + end + + def test_freeze + d = Date.new + d.freeze + assert_equal(true, d.frozen?) + assert_instance_of(Fixnum, d.yday) + assert_instance_of(String, d.to_s) + end + + def test_submillisecond_comparison + d1 = DateTime.new(2013, 12, 6, 0, 0, Rational(1, 10000)) + d2 = DateTime.new(2013, 12, 6, 0, 0, Rational(2, 10000)) + # d1 is 0.0001s earlier than d2 + assert_equal(-1, d1 <=> d2) + assert_equal(0, d1 <=> d1) + assert_equal(1, d2 <=> d1) + end + +end diff --git a/jni/ruby/test/date/test_date_arith.rb b/jni/ruby/test/date/test_date_arith.rb new file mode 100644 index 0000000..7b79c18 --- /dev/null +++ b/jni/ruby/test/date/test_date_arith.rb @@ -0,0 +1,264 @@ +require 'test/unit' +require 'date' + +class TestDateArith < Test::Unit::TestCase + + def new_offset + d = DateTime.new(2002, 3, 14) + assert_equal(Rational(9, 24), d.new_offset(Rational(9, 24)).offset) + assert_equal(Rational(9, 24), d.new_offset('+0900').offset) + end + + def test__plus + d = Date.new(2000,2,29) + -1 + assert_equal([2000, 2, 28], [d.year, d.mon, d.mday]) + d = Date.new(2000,2,29) + 0 + assert_equal([2000, 2, 29], [d.year, d.mon, d.mday]) + d = Date.new(2000,2,29) + 1 + assert_equal([2000, 3, 1], [d.year, d.mon, d.mday]) + + d = DateTime.new(2000,2,29) + 1.to_r/2 + assert_equal([2000, 2, 29, 12, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + end + + def test__plus__ex + e = TypeError + assert_raise(e) do + Date.new(2000,2,29) + 'foo' + end + assert_raise(e) do + DateTime.new(2000,2,29) + 'foo' + end + assert_raise(e) do + Date.new(2000,2,29) + Time.mktime(2000,2,29) + end + assert_raise(e) do + DateTime.new(2000,2,29) + Time.mktime(2000,2,29) + end + end + + def test__minus + d = Date.new(2000,3,1) - -1 + assert_equal([2000, 3, 2], [d.year, d.mon, d.mday]) + d = Date.new(2000,3,1) - 0 + assert_equal([2000, 3, 1], [d.year, d.mon, d.mday]) + d = Date.new(2000,3,1) - 1 + assert_equal([2000, 2, 29], [d.year, d.mon, d.mday]) + + d = Date.new(2000,3,1) - Date.new(2000,2,29) + assert_equal(1, d) + d = Date.new(2000,2,29) - Date.new(2000,3,1) + assert_equal(-1, d) + + d = DateTime.new(2000,3,1) - 1.to_r/2 + assert_equal([2000, 2, 29, 12, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + end + + def test__minus__ex + e = TypeError + assert_raise(e) do + Date.new(2000,2,29) - 'foo' + end + assert_raise(e) do + DateTime.new(2000,2,29) - 'foo' + end + assert_raise(e) do + Date.new(2000,2,29) - Time.mktime(2000,2,29) + end + assert_raise(e) do + DateTime.new(2000,2,29) - Time.mktime(2000,2,29) + end + end + + def test__compare + assert_equal(0, (Date.new(2000,1,1) <=> Date.new(2000,1,1))) + assert_equal(-1, (Date.new(2000,1,1) <=> Date.new(2000,1,2))) + assert_equal(1, (Date.new(2000,1,2) <=> Date.new(2000,1,1))) + assert_equal(0, (Date.new(2001,1,4,Date::JULIAN) <=> + Date.new(2001,1,17, Date::GREGORIAN))) + assert_equal(0, (DateTime.new(2001,1,4,0,0,0,0,Date::JULIAN) <=> + DateTime.new(2001,1,17,0,0,0,0,Date::GREGORIAN))) + end + + def test_prev + d = Date.new(2000,1,1) + assert_raise(NoMethodError) do + d.prev + end + end + + def test_prev_day + d = Date.new(2001,1,1).prev_day + assert_equal([2000, 12, 31], [d.year, d.mon, d.mday]) + d = Date.new(2001,1,1).prev_day(2) + assert_equal([2000, 12, 30], [d.year, d.mon, d.mday]) + d = Date.new(2000,12,31).prev_day(-2) + assert_equal([2001, 1, 2], [d.year, d.mon, d.mday]) + + d = DateTime.new(2000,3,1).prev_day(1.to_r/2) + assert_equal([2000, 2, 29, 12, 0, 0], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + end + + def test_prev_month + d = Date.new(2000,1,31) << -1 + assert_equal([2000, 2, 29], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31) << 1 + assert_equal([1999, 12, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31) << 12 + assert_equal([1999, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31) << 14 + assert_equal([1998, 11, 30], [d.year, d.mon, d.mday]) + + end + + def test_prev_month__2 + d = Date.new(2000,1,31).prev_month(-1) + assert_equal([2000, 2, 29], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).prev_month + assert_equal([1999, 12, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).prev_month(12) + assert_equal([1999, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).prev_month(14) + assert_equal([1998, 11, 30], [d.year, d.mon, d.mday]) + end + + def test_prev_year + d = Date.new(2000,1,31).prev_year(-1) + assert_equal([2001, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).prev_year + assert_equal([1999, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).prev_year(10) + assert_equal([1990, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).prev_year(100) + assert_equal([1900, 1, 31], [d.year, d.mon, d.mday]) + end + + def test_next + d = Date.new(2000,12,31).next + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + d = Date.new(2000,12,31).succ + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + + d = Date.today + d2 = d.next + assert_equal(d, (d2 - 1)) + d = Date.today + d2 = d.succ + assert_equal(d, (d2 - 1)) + + d = DateTime.now + d2 = d.next + assert_equal(d, (d2 - 1)) + d = DateTime.now + d2 = d.succ + assert_equal(d, (d2 - 1)) + end + + def test_next_day + d = Date.new(2000,12,31).next_day + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + d = Date.new(2000,12,31).next_day(2) + assert_equal([2001, 1, 2], [d.year, d.mon, d.mday]) + d = Date.new(2001,1,1).next_day(-2) + assert_equal([2000, 12, 30], [d.year, d.mon, d.mday]) + + d = DateTime.new(2000,2,29).next_day(1.to_r/2) + assert_equal([2000, 2, 29, 12, 0, 0], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + end + + def test_next_month + d = Date.new(2000,1,31) >> -1 + assert_equal([1999, 12, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31) >> 1 + assert_equal([2000, 2, 29], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31) >> 12 + assert_equal([2001, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31) >> 13 + assert_equal([2001, 2, 28], [d.year, d.mon, d.mday]) + end + + def test_next_month__2 + d = Date.new(2000,1,31).next_month(-1) + assert_equal([1999, 12, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).next_month + assert_equal([2000, 2, 29], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).next_month(12) + assert_equal([2001, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).next_month(13) + assert_equal([2001, 2, 28], [d.year, d.mon, d.mday]) + end + + def test_next_year + d = Date.new(2000,1,31).next_year(-1) + assert_equal([1999, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).next_year + assert_equal([2001, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).next_year(10) + assert_equal([2010, 1, 31], [d.year, d.mon, d.mday]) + d = Date.new(2000,1,31).next_year(100) + assert_equal([2100, 1, 31], [d.year, d.mon, d.mday]) + end + + def test_downto + p = Date.new(2001,1,14) + q = Date.new(2001,1,7) + i = 0 + p.downto(q) do + i += 1 + end + assert_equal(8, i) + end + + def test_downto__noblock + p = Date.new(2001,1,14) + q = Date.new(2001,1,7) + e = p.downto(q) + assert_equal(8, e.to_a.size) + end + + def test_upto + p = Date.new(2001,1,14) + q = Date.new(2001,1,21) + i = 0 + p.upto(q) do + i += 1 + end + assert_equal(8, i) + end + + def test_upto__noblock + p = Date.new(2001,1,14) + q = Date.new(2001,1,21) + e = p.upto(q) + assert_equal(8, e.to_a.size) + end + + def test_step + p = Date.new(2001,1,14) + q = Date.new(2001,1,21) + i = 0 + p.step(q, 2) do + i += 1 + end + assert_equal(4, i) + + i = 0 + p.step(q) do + i += 1 + end + assert_equal(8, i) + end + + def test_step__noblock + p = Date.new(2001,1,14) + q = Date.new(2001,1,21) + e = p.step(q, 2) + assert_equal(4, e.to_a.size) + + e = p.step(q) + assert_equal(8, e.to_a.size) + end + +end 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 diff --git a/jni/ruby/test/date/test_date_base.rb b/jni/ruby/test/date/test_date_base.rb new file mode 100644 index 0000000..1f3d8c0 --- /dev/null +++ b/jni/ruby/test/date/test_date_base.rb @@ -0,0 +1,442 @@ +require 'test/unit' +require 'date' + +begin + require 'calendar' + include Calendar +rescue LoadError +end + +class TestDateBase < Test::Unit::TestCase + + def setup + if defined?(Calendar) + @from ||= julian_day_number_from_absolute(absolute_from_julian(1, 1, 1601)) + @to ||= julian_day_number_from_absolute(absolute_from_julian(12, 31, 2400)) + @from4t ||= julian_day_number_from_absolute(absolute_from_julian(1, 1, 1970)) + @to4t ||= julian_day_number_from_absolute(absolute_from_julian(12, 31, 2037)) + end + end + + def test__inf + assert_equal(0, Date::Infinity.new(-1) <=> Date::Infinity.new(-1)) + assert_equal(-1, Date::Infinity.new(-1) <=> Date::Infinity.new(+1)) + assert_equal(-1, Date::Infinity.new(-1) <=> 0) + + assert_equal(1, Date::Infinity.new(+1) <=> Date::Infinity.new(-1)) + assert_equal(0, Date::Infinity.new(+1) <=> Date::Infinity.new(+1)) + assert_equal(1, Date::Infinity.new(+1) <=> 0) + + assert_equal(1, 0 <=> Date::Infinity.new(-1)) + assert_equal(-1, 0 <=> Date::Infinity.new(+1)) + assert_equal(0, 0 <=> 0) + + assert_equal(0, Date::ITALY <=> Date::ITALY) + assert_equal(-1, Date::ITALY <=> Date::ENGLAND) + assert_equal(-1, Date::ITALY <=> Date::JULIAN) + assert_equal(1, Date::ITALY <=> Date::GREGORIAN) + + assert_equal(1, Date::ENGLAND <=> Date::ITALY) + assert_equal(0, Date::ENGLAND <=> Date::ENGLAND) + assert_equal(-1, Date::ENGLAND <=> Date::JULIAN) + assert_equal(1, Date::ENGLAND <=> Date::GREGORIAN) + + assert_equal(1, Date::JULIAN <=> Date::ITALY) + assert_equal(1, Date::JULIAN <=> Date::ENGLAND) + assert_equal(0, Date::JULIAN <=> Date::JULIAN) + assert_equal(1, Date::JULIAN <=> Date::GREGORIAN) + + assert_equal(-1, Date::GREGORIAN <=> Date::ITALY) + assert_equal(-1, Date::GREGORIAN <=> Date::ENGLAND) + assert_equal(-1, Date::GREGORIAN <=> Date::JULIAN) + assert_equal(0, Date::GREGORIAN <=> Date::GREGORIAN) + end + + def test_ordinal__julian + skip unless defined?(Calendar) + for j in @from..@to + m, d, y = julian_from_absolute(absolute_from_julian_day_number(j)) + j0 = julian_day_number_from_absolute(absolute_from_julian(12, 31, y - 1)) + j2 = julian_day_number_from_absolute(absolute_from_julian(m, d, y)) + assert_equal(j, j2) + oy, od = Date.__send__(:jd_to_ordinal, j, Date::JULIAN) + assert_equal(y, oy) + assert_equal(j2 - j0, od) + oj = Date.__send__(:ordinal_to_jd, oy, od, Date::JULIAN) + assert_equal(j, oj) + end + end + + def test_ordinal__gregorian + skip unless defined?(Calendar) + for j in @from..@to + m, d, y = gregorian_from_absolute(absolute_from_julian_day_number(j)) + j0 = + julian_day_number_from_absolute(absolute_from_gregorian(12, 31, y - 1)) + j2 = julian_day_number_from_absolute(absolute_from_gregorian(m, d, y)) + assert_equal(j, j2) + oy, od = Date.__send__(:jd_to_ordinal, j, Date::GREGORIAN) + assert_equal(y, oy) + assert_equal(j2 - j0, od) + oj = Date.__send__(:ordinal_to_jd, oy, od, Date::GREGORIAN) + assert_equal(j, oj) + end + end + + def test_civil__julian + skip unless defined?(Calendar) + for j in @from..@to + m, d, y = julian_from_absolute(absolute_from_julian_day_number(j)) + j2 = julian_day_number_from_absolute(absolute_from_julian(m, d, y)) + assert_equal(j2, j) + cy, cm, cd = Date.__send__(:jd_to_civil, j, Date::JULIAN) + assert_equal(y, cy) + assert_equal(m, cm) + assert_equal(d, cd) + cj = Date.__send__(:civil_to_jd, cy, cm, cd, Date::JULIAN) + assert_equal(j, cj) + end + end + + def test_civil__gregorian + skip unless defined?(Calendar) + for j in @from..@to + m, d, y = gregorian_from_absolute(absolute_from_julian_day_number(j)) + j2 = julian_day_number_from_absolute(absolute_from_gregorian(m, d, y)) + assert_equal(j2, j) + cy, cm, cd = Date.__send__(:jd_to_civil, j, Date::GREGORIAN) + assert_equal(y, cy) + assert_equal(m, cm) + assert_equal(d, cd) + cj = Date.__send__(:civil_to_jd, cy, cm, cd, Date::GREGORIAN) + assert_equal(j, cj) + end + end + + def test_commercial__gregorian + skip unless defined?(Calendar) + for j in @from..@to + w, d, y = iso_from_absolute(absolute_from_julian_day_number(j)) + j2 = julian_day_number_from_absolute(absolute_from_iso(w, d, y)) + assert_equal(j2, j) + cy, cw, cd = Date.__send__(:jd_to_commercial, j, Date::GREGORIAN) + assert_equal(y, cy) + assert_equal(w, cw) + assert_equal(d, cd) + cj = Date.__send__(:commercial_to_jd, cy, cw, cd, Date::GREGORIAN) + assert_equal(j, cj) + end + end + + def test_weeknum + skip unless defined?(Calendar) + for j in @from..@to + for k in 0..1 + wy, ww, wd = Date.__send__(:jd_to_weeknum, j, k, Date::GREGORIAN) + wj = Date.__send__(:weeknum_to_jd, wy, ww, wd, k, Date::GREGORIAN) + assert_equal(j, wj) + end + end + end + + def test_weeknum__2 + skip unless defined?(Calendar) + for j in @from4t..@to4t + d = Date.jd(j) + t = Time.mktime(d.year, d.mon, d.mday) + [ + '%Y %U %w', + '%Y %U %u', + '%Y %W %w', + '%Y %W %u' + ].each do |fmt| + s = t.strftime(fmt) + d2 = Date.strptime(s, fmt) + assert_equal(j, d2.jd) + end + end + end + + def test_nth_kday + skip unless defined?(Calendar) + skip unless (Date.respond_to?(:nth_kday_to_jd, true) && + Date.respond_to?(:jd_to_nth_kday, true)) + for y in 1601..2401 + for m in 1..12 + for n in -5..5 + next if n == 0 + for k in 0..6 + j = julian_day_number_from_absolute(Nth_Kday(n, k, m, y)) + j2 = Date.__send__(:nth_kday_to_jd, y, m, n, k, Date::GREGORIAN) + assert_equal(j, j2) + + d1 = Date.__send__(:jd_to_nth_kday, j2, Date::GREGORIAN) + j3 = Date.__send__(:nth_kday_to_jd, *d1) + assert_equal(j, j3) + end + end + end + end + end + + def test_jd + assert_equal(1 << 33, Date.jd(1 << 33).jd) + end + + def test_mjd + skip unless Date.respond_to?(:mjd_to_jd, true) + jd = Date.__send__(:mjd_to_jd, 51321) + mjd = Date.__send__(:jd_to_mjd, jd) + assert_equal(51321, mjd) + end + + def test_ld + skip unless Date.respond_to?(:ld_to_jd, true) + jd = Date.__send__(:ld_to_jd, 152162) + ld = Date.__send__(:jd_to_ld, jd) + assert_equal(152162, ld) + end + + def test_wday + skip unless Date.respond_to?(:jd_to_wday, true) + assert_equal(4, Date.__send__(:jd_to_wday, 3)) + assert_equal(3, Date.__send__(:jd_to_wday, 2)) + assert_equal(2, Date.__send__(:jd_to_wday, 1)) + assert_equal(1, Date.__send__(:jd_to_wday, 0)) + assert_equal(0, Date.__send__(:jd_to_wday, -1)) + assert_equal(6, Date.__send__(:jd_to_wday, -2)) + assert_equal(5, Date.__send__(:jd_to_wday, -3)) + end + + def test_leap? + assert_equal(true, Date.julian_leap?(1900)) + assert_equal(false, Date.julian_leap?(1999)) + assert_equal(true, Date.julian_leap?(2000)) + + assert_equal(false, Date.gregorian_leap?(1900)) + assert_equal(false, Date.gregorian_leap?(1999)) + assert_equal(true, Date.gregorian_leap?(2000)) + + assert_equal(Date.leap?(1990), Date.gregorian_leap?(1900)) + assert_equal(Date.leap?(1999), Date.gregorian_leap?(1999)) + assert_equal(Date.leap?(2000), Date.gregorian_leap?(2000)) + end + + def test_valid_jd + valid_jd_p = :_valid_jd? + skip unless Date.respond_to?(valid_jd_p, true) + assert_equal(-1, Date.__send__(valid_jd_p, -1)) + assert_equal(0, Date.__send__(valid_jd_p, 0)) + assert_equal(1, Date.__send__(valid_jd_p, 1)) + assert_equal(2452348, Date.__send__(valid_jd_p, 2452348)) + end + + def test_valid_ordinal + valid_ordinal_p = :_valid_ordinal? + skip unless Date.respond_to?(valid_ordinal_p, true) + assert_nil(Date.__send__(valid_ordinal_p, 1999,366)) + assert_equal(2451910, Date.__send__(valid_ordinal_p, 2000,366)) + assert_nil(Date.__send__(valid_ordinal_p, 1999,-366)) + assert_equal(2451545, Date.__send__(valid_ordinal_p, 2000,-366)) + assert_equal(2452275, Date.__send__(valid_ordinal_p, 2001,365)) + assert_nil(Date.__send__(valid_ordinal_p, 2001,366)) + assert_equal(Date.__send__(valid_ordinal_p, 2001,1), + Date.__send__(valid_ordinal_p, 2001,-365)) + assert_nil(Date.__send__(valid_ordinal_p, 2001,-366)) + assert_equal(2452348, Date.__send__(valid_ordinal_p, 2002,73)) + end + + def test_valid_ordinal__edge + valid_ordinal_p = :_valid_ordinal? + skip unless Date.respond_to?(valid_ordinal_p, true) + (1601..2400).each do |y| + d = if Date.leap?(y) then 366 else 365 end + assert_not_nil(Date.__send__(valid_ordinal_p, y,d)) + assert_nil(Date.__send__(valid_ordinal_p, y,d + 1)) + assert_not_nil(Date.__send__(valid_ordinal_p, y,-d)) + assert_nil(Date.__send__(valid_ordinal_p, y,-(d + 1))) + end + end + + # October 1582 + # S M Tu W Th F S + # 274 275 276 277 288 289 + # 290 291 292 293 294 295 296 + # 297 298 299 300 301 302 303 + # 304 + + # October 1582 + # S M Tu W Th F S + # -92 -91 -90 -89 -78 -77 + # -76 -75 -74 -73 -72 -71 -70 + # -69 -68 -67 -66 -65 -64 -63 + # -62 + + def test_valid_ordinal__italy + valid_ordinal_p = :_valid_ordinal? + skip unless Date.respond_to?(valid_ordinal_p, true) + (1..355).each do |d| + assert_not_nil(Date.__send__(valid_ordinal_p, 1582,d,Date::ITALY)) + end + (356..365).each do |d| + assert_nil(Date.__send__(valid_ordinal_p, 1582,d,Date::ITALY)) + end + end + + # September 1752 + # S M Tu W Th F S + # 245 246 258 259 260 + # 261 262 263 264 265 266 267 + # 268 269 270 271 272 273 274 + + def test_valid_ordinal__england + valid_ordinal_p = :_valid_ordinal? + skip unless Date.respond_to?(valid_ordinal_p, true) + (1..355).each do |d| + assert_not_nil(Date.__send__(valid_ordinal_p, 1752,d,Date::ENGLAND)) + end + (356..366).each do |d| + assert_nil(Date.__send__(valid_ordinal_p, 1752,d,Date::ENGLAND)) + end + end + + def test_valid_civil + valid_civil_p = :_valid_civil? + skip unless Date.respond_to?(valid_civil_p, true) + assert_nil(Date.__send__(valid_civil_p, 1999,2,29)) + assert_equal(2451604, Date.__send__(valid_civil_p, 2000,2,29)) + assert_nil(Date.__send__(valid_civil_p, 1999,2,-29)) + assert_equal(2451576, Date.__send__(valid_civil_p, 2000,2,-29)) + assert_equal(2451941, Date.__send__(valid_civil_p, 2001,1,31)) + assert_nil(Date.__send__(valid_civil_p, 2001,1,32)) + assert_equal(Date.__send__(valid_civil_p, 2001,1,1), + Date.__send__(valid_civil_p, 2001,1,-31)) + assert_nil(Date.__send__(valid_civil_p, 2001,1,-32)) + assert_equal(2452348, Date.__send__(valid_civil_p, 2002,3,14)) + assert_nil(Date.__send__(valid_civil_p, 2010,-13,-1)) + end + + def test_valid_civil__edge + valid_civil_p = :_valid_civil? + skip unless Date.respond_to?(valid_civil_p, true) + (1601..2400).each do |y| + d = if Date.leap?(y) then 29 else 28 end + assert_not_nil(Date.__send__(valid_civil_p, y,2,d)) + assert_nil(Date.__send__(valid_civil_p, y,2,d + 1)) + assert_not_nil(Date.__send__(valid_civil_p, y,2,-d)) + assert_nil(Date.__send__(valid_civil_p, y,2,-(d + 1))) + end + end + + # October 1582 + # S M Tu W Th F S + # 1 2 3 4 15 16 + # 17 18 19 20 21 22 23 + # 24 25 26 27 28 29 30 + # 31 + + def test_valid_civil__italy + valid_civil_p = :_valid_civil? + skip unless Date.respond_to?(valid_civil_p, true) + (1..4).each do |d| + assert_not_nil(Date.__send__(valid_civil_p, 1582,10,d,Date::ITALY)) + end + (5..14).each do |d| + assert_nil(Date.__send__(valid_civil_p, 1582,10,d,Date::ITALY)) + end + (15..31).each do |d| + assert_not_nil(Date.__send__(valid_civil_p, 1582,10,d,Date::ITALY)) + end + (32..100).each do |d| + assert_nil(Date.__send__(valid_civil_p, 1582,10,d,Date::ITALY)) + end + (-31..-22).each do |d| + assert_nil(Date.__send__(valid_civil_p, 1582,10,d,Date::ITALY)) + end + (-21..-1).each do |d| + assert_not_nil(Date.__send__(valid_civil_p, 1582,10,d,Date::ITALY)) + end + end + + # September 1752 + # S M Tu W Th F S + # 1 2 14 15 16 + # 17 18 19 20 21 22 23 + # 24 25 26 27 28 29 30 + + def test_valid_civil__england + valid_civil_p = :_valid_civil? + skip unless Date.respond_to?(valid_civil_p, true) + (1..2).each do |d| + assert_not_nil(Date.__send__(valid_civil_p, 1752,9,d,Date::ENGLAND)) + end + (3..13).each do |d| + assert_nil(Date.__send__(valid_civil_p, 1752,9,d,Date::ENGLAND)) + end + (14..30).each do |d| + assert_not_nil(Date.__send__(valid_civil_p, 1752,9,d,Date::ENGLAND)) + end + (31..100).each do |d| + assert_nil(Date.__send__(valid_civil_p, 1752,9,d,Date::ENGLAND)) + end + (-31..-20).each do |d| + assert_nil(Date.__send__(valid_civil_p, 1752,9,d,Date::ENGLAND)) + end + (-19..-1).each do |d| + assert_not_nil(Date.__send__(valid_civil_p, 1752,9,d,Date::ENGLAND)) + end + end + + def test_valid_commercial + valid_commercial_p = :_valid_commercial? + skip unless Date.respond_to?(valid_commercial_p, true) + assert_nil(Date.__send__(valid_commercial_p, 1999,53,1)) + assert_equal(2453367, Date.__send__(valid_commercial_p, 2004,53,1)) + assert_nil(Date.__send__(valid_commercial_p, 1999,-53,-1)) + assert_equal(2453009, Date.__send__(valid_commercial_p, 2004,-53,-1)) + assert_equal(2452348, Date.__send__(valid_commercial_p, 2002,11,4)) + end + + def test_valid_weeknum + valid_weeknum_p = :_valid_weeknum? + skip unless Date.respond_to?(valid_weeknum_p, true) + assert_nil(Date.__send__(valid_weeknum_p, 1999,53,0, 0)) + assert_equal(2454101, Date.__send__(valid_weeknum_p, 2006,53,0, 0)) + assert_nil(Date.__send__(valid_weeknum_p, 1999,-53,-1, 0)) + assert_equal(2453743, Date.__send__(valid_weeknum_p, 2006,-53,-1, 0)) + assert_equal(2452355, Date.__send__(valid_weeknum_p, 2002,11,4, 0)) + assert_nil(Date.__send__(valid_weeknum_p, 1999,53,0, 1)) + assert_equal(2454101, Date.__send__(valid_weeknum_p, 2006,52,6, 1)) + assert_nil(Date.__send__(valid_weeknum_p, 1999,-53,-1, 1)) + assert_equal(2453743, Date.__send__(valid_weeknum_p, 2006,-52,-2, 1)) + assert_equal(2452355, Date.__send__(valid_weeknum_p, 2002,11,3, 1)) + end + + def test_valid_nth_kday + valid_nth_kday_p = :_valid_nth_kday? + skip unless Date.respond_to?(valid_nth_kday_p, true) + assert_nil(Date.__send__(valid_nth_kday_p, 1992,2, 5,0)) + assert_equal(2448682, Date.__send__(valid_nth_kday_p, 1992,2, 5,6)) + assert_equal(2448682, Date.__send__(valid_nth_kday_p, 1992,2, 5,-1)) + assert_equal(2448682, Date.__send__(valid_nth_kday_p, 1992,2, -1,6)) + assert_equal(2448682, Date.__send__(valid_nth_kday_p, 1992,2, -1,-1)) + end + + def test_valid_time + valid_time_p = :_valid_time? + skip unless Date.respond_to?(valid_time_p, true) + assert_equal(Rational(0), DateTime.__send__(valid_time_p, 0,0,0)) + assert_nil(DateTime.__send__(valid_time_p, 25,59,59)) + assert_nil(DateTime.__send__(valid_time_p, 23,60,59)) + assert_nil(DateTime.__send__(valid_time_p, 23,59,60)) + assert_equal(Rational(86399, 86400), + DateTime.__send__(valid_time_p, 23,59,59)) + assert_equal(Rational(86399, 86400), + DateTime.__send__(valid_time_p, -1,-1,-1)) + assert_equal(Rational(1), DateTime.__send__(valid_time_p, 24,0,0)) + assert_nil(DateTime.__send__(valid_time_p, 24,0,1)) + assert_nil(DateTime.__send__(valid_time_p, 24,1,0)) + assert_nil(DateTime.__send__(valid_time_p, 24,1,1)) + end + +end diff --git a/jni/ruby/test/date/test_date_compat.rb b/jni/ruby/test/date/test_date_compat.rb new file mode 100644 index 0000000..8284007 --- /dev/null +++ b/jni/ruby/test/date/test_date_compat.rb @@ -0,0 +1,21 @@ +require 'test/unit' +require 'date' + +class TestDateCompat < Test::Unit::TestCase + + def test_compat + assert_equal(DateTime.new, Date.new) + assert_equal(DateTime.new(2002,3,19), Date.new(2002,3,19)) + assert_equal(DateTime.new(2002,3,19, 0,0,0), Date.new(2002,3,19)) + assert_equal(DateTime.new(2002,3,19, 0,0,0, 0), Date.new(2002,3,19)) + assert_equal(DateTime.new(2002,3,19, 0,0,0, 0.to_r), Date.new(2002,3,19)) + assert_equal(DateTime.new(2002,3,19, 0,0,0, 0, Date::GREGORIAN), Date.new(2002,3,19, Date::GREGORIAN)) + assert_equal(DateTime.new(2002,3,19, 0,0,0, 0, Date::JULIAN), Date.new(2002,3,19, Date::JULIAN)) + + assert(Date.new(2002,3,19) != DateTime.new(2002,3,19, 12,0,0)) + assert(Date.new(2002,3,19) != DateTime.new(2002,3,19, 0,0,1)) + assert(Date.new(2002,3,19) === DateTime.new(2002,3,19, 12,0,0)) + assert(Date.new(2002,3,19) === DateTime.new(2002,3,19, 0,0,1)) + end + +end diff --git a/jni/ruby/test/date/test_date_conv.rb b/jni/ruby/test/date/test_date_conv.rb new file mode 100644 index 0000000..daf0374 --- /dev/null +++ b/jni/ruby/test/date/test_date_conv.rb @@ -0,0 +1,137 @@ +require 'test/unit' +require 'date' + +class TestDateConv < Test::Unit::TestCase + + def test_to_class + [Time.now, Date.today, DateTime.now].each do |o| + assert_instance_of(Time, o.to_time) + assert_instance_of(Date, o.to_date) + assert_instance_of(DateTime, o.to_datetime) + end + end + + def test_to_time__from_time + t = Time.mktime(2004, 9, 19, 1, 2, 3, 456789) + t2 = t.to_time + assert_equal([2004, 9, 19, 1, 2, 3, 456789], + [t2.year, t2.mon, t2.mday, t2.hour, t2.min, t2.sec, t2.usec]) + + t = Time.utc(2004, 9, 19, 1, 2, 3, 456789) + t2 = t.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, 456789], + [t2.year, t2.mon, t2.mday, t2.hour, t2.min, t2.sec, t2.usec]) + end + + def test_to_time__from_date + d = Date.new(2004, 9, 19) + t = d.to_time + assert_equal([2004, 9, 19, 0, 0, 0, 0], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) + end + + def test_to_time__from_datetime + d = DateTime.new(2004, 9, 19, 1, 2, 3, 9.to_r/24) + 456789.to_r/86400000000 + t = d.to_time + if t.utc_offset == 9*60*60 + assert_equal([2004, 9, 19, 1, 2, 3, 456789], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) + end + + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789.to_r/86400000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, 456789], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) + + if Time.allocate.respond_to?(:nsec) + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, 456789123], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) + end + + if Time.allocate.respond_to?(:subsec) + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) + end + end + + def test_to_date__from_time + t = Time.mktime(2004, 9, 19, 1, 2, 3, 456789) + d = t.to_date + assert_equal([2004, 9, 19, 0], [d.year, d.mon, d.mday, d.day_fraction]) + + t = Time.utc(2004, 9, 19, 1, 2, 3, 456789) + d = t.to_date + assert_equal([2004, 9, 19, 0], [d.year, d.mon, d.mday, d.day_fraction]) + end + + def test_to_date__from_date + d = Date.new(2004, 9, 19) + 1.to_r/2 + d2 = d.to_date + assert_equal([2004, 9, 19, 1.to_r/2], + [d2.year, d2.mon, d2.mday, d2.day_fraction]) + end + + def test_to_date__from_datetime + d = DateTime.new(2004, 9, 19, 1, 2, 3, 9.to_r/24) + 456789.to_r/86400000000 + d2 = d.to_date + assert_equal([2004, 9, 19, 0], [d2.year, d2.mon, d2.mday, d2.day_fraction]) + + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789.to_r/86400000000 + d2 = d.to_date + assert_equal([2004, 9, 19, 0], [d2.year, d2.mon, d2.mday, d2.day_fraction]) + end + + def test_to_datetime__from_time + t = Time.mktime(2004, 9, 19, 1, 2, 3, 456789) + d = t.to_datetime + assert_equal([2004, 9, 19, 1, 2, 3, + 456789.to_r/1000000, + t.utc_offset.to_r/86400], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, + d.sec_fraction, d.offset]) + + t = Time.utc(2004, 9, 19, 1, 2, 3, 456789) + d = t.to_datetime + assert_equal([2004, 9, 19, 1, 2, 3, + 456789.to_r/1000000, + 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, + d.sec_fraction, d.offset]) + + t = Time.now + d = t.to_datetime + require 'time' + assert_equal(t.iso8601(10), d.iso8601(10)) + end + + def test_to_datetime__from_date + d = Date.new(2004, 9, 19) + 1.to_r/2 + d2 = d.to_datetime + assert_equal([2004, 9, 19, 0, 0, 0, 0, 0], + [d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec, + d2.sec_fraction, d2.offset]) + end + + def test_to_datetime__from_datetime + d = DateTime.new(2004, 9, 19, 1, 2, 3, 9.to_r/24) + 456789.to_r/86400000000 + d2 = d.to_datetime + assert_equal([2004, 9, 19, 1, 2, 3, + 456789.to_r/1000000, + 9.to_r/24], + [d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec, + d2.sec_fraction, d2.offset]) + + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789.to_r/86400000000 + d2 = d.to_datetime + assert_equal([2004, 9, 19, 1, 2, 3, + 456789.to_r/1000000, + 0], + [d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec, + d2.sec_fraction, d2.offset]) + end + +end diff --git a/jni/ruby/test/date/test_date_marshal.rb b/jni/ruby/test/date/test_date_marshal.rb new file mode 100644 index 0000000..4ea5565 --- /dev/null +++ b/jni/ruby/test/date/test_date_marshal.rb @@ -0,0 +1,41 @@ +require 'test/unit' +require 'date' + +class TestDateMarshal < Test::Unit::TestCase + + def test_marshal + d = Date.new + m = Marshal.dump(d) + d2 = Marshal.load(m) + assert_equal(d, d2) + assert_equal(d.start, d2.start) + assert_instance_of(String, d2.to_s) + + d = Date.today + m = Marshal.dump(d) + d2 = Marshal.load(m) + assert_equal(d, d2) + assert_equal(d.start, d2.start) + assert_instance_of(String, d2.to_s) + + d = DateTime.now + m = Marshal.dump(d) + d2 = Marshal.load(m) + assert_equal(d, d2) + assert_equal(d.start, d2.start) + assert_instance_of(String, d2.to_s) + + d = Date.today + a = d.marshal_dump + d.freeze + assert(d.frozen?) + assert_raise(RuntimeError){d.marshal_load(a)} + + d = DateTime.now + a = d.marshal_dump + d.freeze + assert(d.frozen?) + assert_raise(RuntimeError){d.marshal_load(a)} + end + +end diff --git a/jni/ruby/test/date/test_date_new.rb b/jni/ruby/test/date/test_date_new.rb new file mode 100644 index 0000000..0bbbfee --- /dev/null +++ b/jni/ruby/test/date/test_date_new.rb @@ -0,0 +1,271 @@ +require 'test/unit' +require 'date' + +class TestDateNew < Test::Unit::TestCase + + def test_jd + d = Date.jd + dt = DateTime.jd + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + assert_equal([-4712, 1, 1], [dt.year, dt.mon, dt.mday]) + assert_equal([0, 0, 0], [dt.hour, dt.min, dt.sec]) + + d2 = Date.jd + dt2 = DateTime.jd + assert_equal(d, d2) + assert_equal(dt, dt2) + + d = Date.jd(0) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + d = DateTime.jd(0, 0,0,0, 0) + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(0, 0,0,0, '+0900') + assert_equal([-4712, 1, 1, 0, 0, 0, 9.to_r/24], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_jd__ex + assert_raise(ArgumentError) do + DateTime.jd(0, 23,59,60,0) + end + end + + def test_ordinal + d = Date.ordinal + dt = DateTime.ordinal + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + assert_equal([-4712, 1, 1], [dt.year, dt.mon, dt.mday]) + assert_equal([0, 0, 0], [dt.hour, dt.min, dt.sec]) + + d2 = Date.ordinal + dt2 = DateTime.ordinal + assert_equal(d, d2) + assert_equal(dt, dt2) + + d = Date.ordinal(-4712,1) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + + d = Date.ordinal(-4712,1.0) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + + d = DateTime.ordinal(-4712,1, 0,0,0, 0) + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(-4712,1, 0,0,0, '+0900') + assert_equal([-4712, 1, 1, 0, 0, 0, 9.to_r/24], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_ordinal__neg + d = Date.ordinal(-1,-1) + assert_equal([-1, 365], [d.year, d.yday]) + + d = DateTime.ordinal(-1,-1, -1,-1,-1, 0) + assert_equal([-1, 365, 23, 59, 59, 0], + [d.year, d.yday, d.hour, d.min, d.sec, d.offset]) + end + + def test_ordinal__ex + assert_raise(ArgumentError) do + Date.ordinal(2001,366) + end + assert_raise(ArgumentError) do + DateTime.ordinal(2001,365, 23,59,60, 0) + end + end + + def test_civil + d = Date.civil + dt = DateTime.civil + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + assert_equal([-4712, 1, 1], [dt.year, dt.mon, dt.mday]) + assert_equal([0, 0, 0], [dt.hour, dt.min, dt.sec]) + + d2 = Date.civil + dt2 = DateTime.civil + assert_equal(d, d2) + assert_equal(dt, dt2) + + d = Date.civil(-4712,1,1) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + + d = Date.civil(-4712,1,1.0) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + + d = DateTime.civil(-4712,1,1, 0,0,0, 0) + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.civil(-4712,1,1, 0,0,0, '+0900') + assert_equal([-4712, 1, 1, 0, 0, 0, 9.to_r/24], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + + + d = DateTime.civil(2001,2,3 + 1.to_r/2) + assert_equal([2001, 2, 3, 12, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.civil(2001,2,3, 4 + 1.to_r/2) + assert_equal([2001, 2, 3, 4, 30, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.civil(2001,2,3, 4,5 + 1.to_r/2) + assert_equal([2001, 2, 3, 4, 5, 30, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.civil(2001,2,3, 4,5,6 + 1.to_r/2) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + assert_equal(1.to_r/2, d.sec_fraction) + end + + def test_civil__neg + d = Date.civil(-1,-1,-1) + assert_equal([-1, 12, 31], [d.year, d.mon, d.mday]) + + d = DateTime.civil(-1,-1,-1, -1,-1,-1, 0) + assert_equal([-1, 12, 31, 23, 59, 59, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_civil__ex + assert_raise(ArgumentError) do + Date.civil(2001,2,29) + end + assert_raise(ArgumentError) do + DateTime.civil(2001,2,28, 23,59,60, 0) + end + assert_raise(ArgumentError) do + DateTime.civil(2001,2,28, 24,59,59, 0) + end + end + + def test_civil__reform + d = Date.jd(Date::ENGLAND, Date::ENGLAND) + dt = DateTime.jd(Date::ENGLAND, 0,0,0,0, Date::ENGLAND) + assert_equal([1752, 9, 14], [d.year, d.mon, d.mday]) + assert_equal([1752, 9, 14], [dt.year, dt.mon, dt.mday]) + d -= 1 + dt -= 1 + assert_equal([1752, 9, 2], [d.year, d.mon, d.mday]) + assert_equal([1752, 9, 2], [dt.year, dt.mon, dt.mday]) + + d = Date.jd(Date::ITALY, Date::ITALY) + dt = DateTime.jd(Date::ITALY, 0,0,0,0, Date::ITALY) + assert_equal([1582, 10, 15], [d.year, d.mon, d.mday]) + assert_equal([1582, 10, 15], [dt.year, dt.mon, dt.mday]) + d -= 1 + dt -= 1 + assert_equal([1582, 10, 4], [d.year, d.mon, d.mday]) + assert_equal([1582, 10, 4], [dt.year, dt.mon, dt.mday]) + end + + def test_commercial + d = Date.commercial + dt = DateTime.commercial + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + assert_equal([-4712, 1, 1], [dt.year, dt.mon, dt.mday]) + assert_equal([0, 0, 0], [dt.hour, dt.min, dt.sec]) + + d2 = Date.commercial + dt2 = DateTime.commercial + assert_equal(d, d2) + assert_equal(dt, dt2) + + d = Date.commercial(1582,40,5) + assert_equal([1582, 10, 15], [d.year, d.mon, d.mday]) + + d = Date.commercial(1582,40,5.0) + assert_equal([1582, 10, 15], [d.year, d.mon, d.mday]) + + d = DateTime.commercial(1582,40,5, 0,0,0, 0) + assert_equal([1582, 10, 15, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(1582,40,5, 0,0,0, '+0900') + assert_equal([1582, 10, 15, 0, 0, 0, 9.to_r/24], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_commercial__neg + d = Date.commercial(1998,-1,-1) + assert_equal([1999, 1, 3], [d.year, d.mon, d.mday]) + + d = DateTime.commercial(1998,-1,-1, -1,-1,-1, 0) + assert_equal([1999, 1, 3, 23, 59, 59, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_commercial__ex + assert_raise(ArgumentError) do + Date.commercial(1997,53,1) + end + assert_raise(ArgumentError) do + DateTime.commercial(1997,52,1, 23,59,60, 0) + end + end + + def test_weeknum + skip unless Date.respond_to?(:weeknum, true) + d = Date.__send__(:weeknum) + dt = DateTime.__send__(:weeknum) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + assert_equal([-4712, 1, 1], [dt.year, dt.mon, dt.mday]) + assert_equal([0, 0, 0], [dt.hour, dt.min, dt.sec]) + + d = Date.__send__(:weeknum, 2002,11,4, 0) + assert_equal(2452355, d.jd) + + d = DateTime.__send__(:weeknum, 2002,11,4, 0, 11,22,33) + assert_equal(2452355, d.jd) + assert_equal([11,22,33], [d.hour, d.min, d.sec]) + + assert_raise(ArgumentError) do + Date.__send__(:weeknum, 1999,53,0, 0) + end + assert_raise(ArgumentError) do + Date.__send__(:weeknum, 1999,-53,-1, 0) + end + end + + def test_nth_kday + skip unless Date.respond_to?(:nth_kday, true) + d = Date.__send__(:nth_kday) + dt = DateTime.__send__(:nth_kday) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + assert_equal([-4712, 1, 1], [dt.year, dt.mon, dt.mday]) + assert_equal([0, 0, 0], [dt.hour, dt.min, dt.sec]) + + d = Date.__send__(:nth_kday, 1992,2, 5,6) + assert_equal(2448682, d.jd) + + d = DateTime.__send__(:nth_kday, 1992,2, 5,6, 11,22,33) + assert_equal(2448682, d.jd) + assert_equal([11,22,33], [d.hour, d.min, d.sec]) + + assert_raise(ArgumentError) do + Date.__send__(:nth_kday, 2006,5, 5,0) + end + assert_raise(ArgumentError) do + Date.__send__(:nth_kday, 2006,5, -5,0) + end + end + + def test_today + z = Time.now + d = Date.today + t = Time.now + t2 = Time.utc(t.year, t.mon, t.mday) + t3 = Time.utc(d.year, d.mon, d.mday) + assert_in_delta(t2, t3, t - z + 2) + + assert_equal(false, DateTime.respond_to?(:today)) + end + + def test_now + assert_equal(false, Date.respond_to?(:now)) + + z = Time.now + d = DateTime.now + t = Time.now + t2 = Time.local(d.year, d.mon, d.mday, d.hour, d.min, d.sec) + assert_in_delta(t, t2, t - z + 2) + end + +end diff --git a/jni/ruby/test/date/test_date_parse.rb b/jni/ruby/test/date/test_date_parse.rb new file mode 100644 index 0000000..e0cd602 --- /dev/null +++ b/jni/ruby/test/date/test_date_parse.rb @@ -0,0 +1,1124 @@ +require 'test/unit' +require 'date' + +class TestDateParse < Test::Unit::TestCase + + def test__parse + [ + # ctime(3), asctime(3) + [['Sat Aug 28 02:55:50 1999',false],[1999,8,28,2,55,50,nil,nil,6], __LINE__], + [['Sat Aug 28 02:55:50 02',false],[2,8,28,2,55,50,nil,nil,6], __LINE__], + [['Sat Aug 28 02:55:50 02',true],[2002,8,28,2,55,50,nil,nil,6], __LINE__], + [['Sat Aug 28 02:55:50 0002',false],[2,8,28,2,55,50,nil,nil,6], __LINE__], + [['Sat Aug 28 02:55:50 0002',true],[2,8,28,2,55,50,nil,nil,6], __LINE__], + + # date(1) + [['Sat Aug 28 02:29:34 JST 1999',false],[1999,8,28,2,29,34,'JST',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 MET DST 1999',false],[1999,8,28,2,29,34,'MET DST',2*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 AMT 1999',false],[1999,8,28,2,29,34,'AMT',nil,6], __LINE__], + [['Sat Aug 28 02:29:34 PMT 1999',false],[1999,8,28,2,29,34,'PMT',nil,6], __LINE__], + [['Sat Aug 28 02:29:34 PMT -1999',false],[-1999,8,28,2,29,34,'PMT',nil,6], __LINE__], + + [['Sat Aug 28 02:29:34 JST 02',false],[2,8,28,2,29,34,'JST',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 JST 02',true],[2002,8,28,2,29,34,'JST',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 JST 0002',false],[2,8,28,2,29,34,'JST',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 JST 0002',true],[2,8,28,2,29,34,'JST',9*3600,6], __LINE__], + + [['Sat Aug 28 02:29:34 GMT+09 0002',false],[2,8,28,2,29,34,'GMT+09',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT+0900 0002',false],[2,8,28,2,29,34,'GMT+0900',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT+09:00 0002',false],[2,8,28,2,29,34,'GMT+09:00',9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT-09 0002',false],[2,8,28,2,29,34,'GMT-09',-9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT-0900 0002',false],[2,8,28,2,29,34,'GMT-0900',-9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT-09:00 0002',false],[2,8,28,2,29,34,'GMT-09:00',-9*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT-090102 0002',false],[2,8,28,2,29,34,'GMT-090102',-9*3600-60-2,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT-09:01:02 0002',false],[2,8,28,2,29,34,'GMT-09:01:02',-9*3600-60-2,6], __LINE__], + + [['Sat Aug 28 02:29:34 GMT Standard Time 2000',false],[2000,8,28,2,29,34,'GMT Standard Time',0*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 Mountain Standard Time 2000',false],[2000,8,28,2,29,34,'Mountain Standard Time',-7*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 Mountain Daylight Time 2000',false],[2000,8,28,2,29,34,'Mountain Daylight Time',-6*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 Mexico Standard Time 2000',false],[2000,8,28,2,29,34,'Mexico Standard Time',-6*3600,6], __LINE__], + [['Sat Aug 28 02:29:34 E. Australia Standard Time 2000',false],[2000,8,28,2,29,34,'E. Australia Standard Time',10*3600,6], __LINE__], + + # part of iso 8601 + [['1999-05-23 23:55:21',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['1999-05-23 23:55:21+0900',false],[1999,5,23,23,55,21,'+0900',9*3600,nil], __LINE__], + [['1999-05-23 23:55:21-0900',false],[1999,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['1999-05-23 23:55:21+09:00',false],[1999,5,23,23,55,21,'+09:00',9*3600,nil], __LINE__], + [['1999-05-23T23:55:21-09:00',false],[1999,5,23,23,55,21,'-09:00',-9*3600,nil], __LINE__], + [['1999-05-23 23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__], + [['1999-05-23T23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__], + [['-1999-05-23T23:55:21Z',false],[-1999,5,23,23,55,21,'Z',0,nil], __LINE__], + [['-1999-05-23T23:55:21Z',true],[-1999,5,23,23,55,21,'Z',0,nil], __LINE__], + [['19990523T23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__], + + [['+011985-04-12',false],[11985,4,12,nil,nil,nil,nil,nil,nil], __LINE__], + [['+011985-04-12T10:15:30',false],[11985,4,12,10,15,30,nil,nil,nil], __LINE__], + [['-011985-04-12',false],[-11985,4,12,nil,nil,nil,nil,nil,nil], __LINE__], + [['-011985-04-12T10:15:30',false],[-11985,4,12,10,15,30,nil,nil,nil], __LINE__], + + [['02-04-12',false],[2,4,12,nil,nil,nil,nil,nil,nil], __LINE__], + [['02-04-12',true],[2002,4,12,nil,nil,nil,nil,nil,nil], __LINE__], + [['0002-04-12',false],[2,4,12,nil,nil,nil,nil,nil,nil], __LINE__], + [['0002-04-12',true],[2,4,12,nil,nil,nil,nil,nil,nil], __LINE__], + + [['19990523',true],[1999,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['-19990523',true],[-1999,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['990523',true],[1999,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['0523',false],[nil,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['23',false],[nil,nil,23,nil,nil,nil,nil,nil,nil], __LINE__], + + [['19990523 235521',true],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['990523 235521',true],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['0523 2355',false],[nil,5,23,23,55,nil,nil,nil,nil], __LINE__], + [['23 2355',false],[nil,nil,23,23,55,nil,nil,nil,nil], __LINE__], + + [['19990523T235521',true],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['990523T235521',true],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['19990523T235521.99',true],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['990523T235521.99',true],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['0523T2355',false],[nil,5,23,23,55,nil,nil,nil,nil], __LINE__], + + [['19990523T235521+0900',true],[1999,5,23,23,55,21,'+0900',9*3600,nil], __LINE__], + [['990523T235521-0900',true],[1999,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['19990523T235521.99+0900',true],[1999,5,23,23,55,21,'+0900',9*3600,nil], __LINE__], + [['990523T235521.99-0900',true],[1999,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['0523T2355Z',false],[nil,5,23,23,55,nil,'Z',0,nil], __LINE__], + + [['19990523235521.123456+0900',true],[1999,5,23,23,55,21,'+0900',9*3600,nil], __LINE__], + [['19990523235521.123456-0900',true],[1999,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['19990523235521,123456+0900',true],[1999,5,23,23,55,21,'+0900',9*3600,nil], __LINE__], + [['19990523235521,123456-0900',true],[1999,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + + [['990523235521,123456-0900',false],[99,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['0523235521,123456-0900',false],[nil,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['23235521,123456-0900',false],[nil,nil,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['235521,123456-0900',false],[nil,nil,nil,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['5521,123456-0900',false],[nil,nil,nil,nil,55,21,'-0900',-9*3600,nil], __LINE__], + [['21,123456-0900',false],[nil,nil,nil,nil,nil,21,'-0900',-9*3600,nil], __LINE__], + + [['3235521,123456-0900',false],[nil,nil,3,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['35521,123456-0900',false],[nil,nil,nil,3,55,21,'-0900',-9*3600,nil], __LINE__], + [['521,123456-0900',false],[nil,nil,nil,nil,5,21,'-0900',-9*3600,nil], __LINE__], + + # reversed iso 8601 (?) + [['23-05-1999',false],[1999,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['23-05-1999 23:55:21',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['23-05--1999 23:55:21',false],[-1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [["23-05-'99",false],[99,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [["23-05-'99",true],[1999,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + + # broken iso 8601 (?) + [['19990523T23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__], + [['19990523235521.1234-100',true],[1999,5,23,23,55,21,'-100',-1*3600,nil], __LINE__], + [['19990523235521.1234-10',true],[1999,5,23,23,55,21,'-10',-10*3600,nil], __LINE__], + + # part of jis x0301 + [['M11.05.23',false],[1878,5,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['T11.05.23 23:55:21+0900',false],[1922,5,23,23,55,21,'+0900',9*3600,nil], __LINE__], + [['S11.05.23 23:55:21-0900',false],[1936,5,23,23,55,21,'-0900',-9*3600,nil], __LINE__], + [['S40.05.23 23:55:21+09:00',false],[1965,5,23,23,55,21,'+09:00',9*3600,nil], __LINE__], + [['S40.05.23T23:55:21-09:00',false],[1965,5,23,23,55,21,'-09:00',-9*3600,nil], __LINE__], + [['H11.05.23 23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__], + [['H11.05.23T23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__], + + # ofx date + [['19990523235521',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['19990523235521.123',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__], + [['19990523235521.123[-9]',false],[1999,5,23,23,55,21,'-9',-(9*3600),nil], __LINE__], + [['19990523235521.123[+9]',false],[1999,5,23,23,55,21,'+9',+(9*3600),nil], __LINE__], + [['19990523235521.123[9]',false],[1999,5,23,23,55,21,'9',+(9*3600),nil], __LINE__], + [['19990523235521.123[-9.50]',false],[1999,5,23,23,55,21,'-9.50',-(9*3600+30*60),nil], __LINE__], + [['19990523235521.123[+9.50]',false],[1999,5,23,23,55,21,'+9.50',+(9*3600+30*60),nil], __LINE__], + [['19990523235521.123[-5:EST]',false],[1999,5,23,23,55,21,'EST',-5*3600,nil], __LINE__], + [['19990523235521.123[+9:JST]',false],[1999,5,23,23,55,21,'JST',9*3600,nil], __LINE__], + [['19990523235521.123[+12:XXX YYY ZZZ]',false],[1999,5,23,23,55,21,'XXX YYY ZZZ',12*3600,nil], __LINE__], + [['235521.123',false],[nil,nil,nil,23,55,21,nil,nil,nil], __LINE__], + [['235521.123[-9]',false],[nil,nil,nil,23,55,21,'-9',-9*3600,nil], __LINE__], + [['235521.123[+9]',false],[nil,nil,nil,23,55,21,'+9',+9*3600,nil], __LINE__], + [['235521.123[-5:EST]',false],[nil,nil,nil,23,55,21,'EST',-5*3600,nil], __LINE__], + [['235521.123[+9:JST]',false],[nil,nil,nil,23,55,21,'JST',+9*3600,nil], __LINE__], + + # rfc 2822 + [['Sun, 22 Aug 1999 00:45:29 -0400',false],[1999,8,22,0,45,29,'-0400',-4*3600,0], __LINE__], + [['Sun, 22 Aug 1999 00:45:29 -9959',false],[1999,8,22,0,45,29,'-9959',-(99*3600+59*60),0], __LINE__], + [['Sun, 22 Aug 1999 00:45:29 +9959',false],[1999,8,22,0,45,29,'+9959',+(99*3600+59*60),0], __LINE__], + [['Sun, 22 Aug 05 00:45:29 -0400',true],[2005,8,22,0,45,29,'-0400',-4*3600,0], __LINE__], + [['Sun, 22 Aug 49 00:45:29 -0400',true],[2049,8,22,0,45,29,'-0400',-4*3600,0], __LINE__], + [['Sun, 22 Aug 1999 00:45:29 GMT',false],[1999,8,22,0,45,29,'GMT',0,0], __LINE__], + [["Sun,\00022\r\nAug\r\n1999\r\n00:45:29\r\nGMT",false],[1999,8,22,0,45,29,'GMT',0,0], __LINE__], + [['Sun, 22 Aug 1999 00:45 GMT',false],[1999,8,22,0,45,nil,'GMT',0,0], __LINE__], + [['Sun, 22 Aug -1999 00:45 GMT',false],[-1999,8,22,0,45,nil,'GMT',0,0], __LINE__], + [['Sun, 22 Aug 99 00:45:29 UT',true],[1999,8,22,0,45,29,'UT',0,0], __LINE__], + [['Sun, 22 Aug 0099 00:45:29 UT',true],[99,8,22,0,45,29,'UT',0,0], __LINE__], + + # rfc 850, obsoleted by rfc 1036 + [['Tuesday, 02-Mar-99 11:20:32 GMT',true],[1999,3,2,11,20,32,'GMT',0,2], __LINE__], + + # W3C Working Draft - XForms - 4.8 Time + [['2000-01-31 13:20:00-5',false],[2000,1,31,13,20,0,'-5',-5*3600,nil], __LINE__], + + # [-+]\d+.\d+ + [['2000-01-31 13:20:00-5.5',false],[2000,1,31,13,20,0,'-5.5',-5*3600-30*60,nil], __LINE__], + [['2000-01-31 13:20:00-5,5',false],[2000,1,31,13,20,0,'-5,5',-5*3600-30*60,nil], __LINE__], + [['2000-01-31 13:20:00+3.5',false],[2000,1,31,13,20,0,'+3.5',3*3600+30*60,nil], __LINE__], + [['2000-01-31 13:20:00+3,5',false],[2000,1,31,13,20,0,'+3,5',3*3600+30*60,nil], __LINE__], + + # mil + [['2000-01-31 13:20:00 Z',false],[2000,1,31,13,20,0,'Z',0*3600,nil], __LINE__], + [['2000-01-31 13:20:00 H',false],[2000,1,31,13,20,0,'H',8*3600,nil], __LINE__], + [['2000-01-31 13:20:00 M',false],[2000,1,31,13,20,0,'M',12*3600,nil], __LINE__], + [['2000-01-31 13:20 M',false],[2000,1,31,13,20,nil,'M',12*3600,nil], __LINE__], + [['2000-01-31 13:20:00 S',false],[2000,1,31,13,20,0,'S',-6*3600,nil], __LINE__], + [['2000-01-31 13:20:00 A',false],[2000,1,31,13,20,0,'A',1*3600,nil], __LINE__], + [['2000-01-31 13:20:00 P',false],[2000,1,31,13,20,0,'P',-3*3600,nil], __LINE__], + + # dot + [['1999.5.2',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['1999.05.02',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['-1999.05.02',false],[-1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [['0099.5.2',false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['0099.5.2',true],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [["'99.5.2",false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [["'99.5.2",true],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + # reversed dot + [['2.5.1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['02.05.1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['02.05.-1999',false],[-1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [['2.5.0099',false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['2.5.0099',true],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [["2.5.'99",false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [["2.5.'99",true],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + # vms + [['08-DEC-1988',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['31-JAN-1999',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['31-JAN--1999',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + + [['08-DEC-88',false],[88,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['08-DEC-88',true],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['08-DEC-0088',false],[88,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['08-DEC-0088',true],[88,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + + # swaped vms + [['DEC-08-1988',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['JAN-31-1999',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['JAN-31--1999',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['JAN-1999',false],[1999,1,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['JAN--1999',false],[-1999,1,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + # reversed vms + [['1988-DEC-08',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['1999-JAN-31',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['-1999-JAN-31',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + + [['0088-DEC-08',false],[88,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['0088-DEC-08',true],[88,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + + [["'88/12/8",false],[88,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [["'88/12/8",true],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + + # non-spaced eu + [['08/dec/1988',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['31/jan/1999',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['31/jan/-1999',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['08.dec.1988',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['31.jan.1999',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['31.jan.-1999',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + + # non-spaced us + [['dec/08/1988',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan/31/1999',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan/31/-1999',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan/31',false],[nil,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan/1988',false],[1988,1,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['dec.08.1988',false],[1988,12,8,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan.31.1999',false],[1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan.31.-1999',false],[-1999,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan.31',false],[nil,1,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['jan.1988',false],[1988,1,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + # month and day of month + [['Jan 1',false],[nil,1,1,nil,nil,nil,nil,nil,nil], __LINE__], + [['Jul 11',false],[nil,7,11,nil,nil,nil,nil,nil,nil], __LINE__], + [['July 11',false],[nil,7,11,nil,nil,nil,nil,nil,nil], __LINE__], + [['Sept 23',false],[nil,9,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['Sep. 23',false],[nil,9,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['Sept. 23',false],[nil,9,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['September 23',false],[nil,9,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['October 1st',false],[nil,10,1,nil,nil,nil,nil,nil,nil], __LINE__], + [['October 23rd',false],[nil,10,23,nil,nil,nil,nil,nil,nil], __LINE__], + [['October 25th 1999',false],[1999,10,25,nil,nil,nil,nil,nil,nil], __LINE__], + [['October 25th -1999',false],[-1999,10,25,nil,nil,nil,nil,nil,nil], __LINE__], + [['october 25th 1999',false],[1999,10,25,nil,nil,nil,nil,nil,nil], __LINE__], + [['OCTOBER 25th 1999',false],[1999,10,25,nil,nil,nil,nil,nil,nil], __LINE__], + [['oCtoBer 25th 1999',false],[1999,10,25,nil,nil,nil,nil,nil,nil], __LINE__], + [['aSep 23',false],[nil,nil,23,nil,nil,nil,nil,nil,nil], __LINE__], + + # month and year + [['Sept 1990',false],[1990,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["Sept '90",false],[90,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["Sept '90",true],[1990,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['1990/09',false],[1990,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['09/1990',false],[1990,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["aSep '90",false],[90,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + # year + [["'90",false],[90,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["'90",true],[1990,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + # month + [['Jun',false],[nil,6,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['June',false],[nil,6,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['Sep',false],[nil,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['Sept',false],[nil,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['September',false],[nil,9,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['aSep',false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + # day of month + [['1st',false],[nil,nil,1,nil,nil,nil,nil,nil,nil], __LINE__], + [['2nd',false],[nil,nil,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['3rd',false],[nil,nil,3,nil,nil,nil,nil,nil,nil], __LINE__], + [['4th',false],[nil,nil,4,nil,nil,nil,nil,nil,nil], __LINE__], + [['29th',false],[nil,nil,29,nil,nil,nil,nil,nil,nil], __LINE__], + [['31st',false],[nil,nil,31,nil,nil,nil,nil,nil,nil], __LINE__], + [['1sta',false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + # era + [['Sat Aug 28 02:29:34 GMT CE 2000',false],[2000,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT C.E. 2000',false],[2000,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT BCE 2000',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT B.C.E. 2000',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT AD 2000',false],[2000,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT A.D. 2000',false],[2000,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT BC 2000',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT B.C. 2000',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT 2000 BC',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT 2000 BCE',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT 2000 B.C.',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + [['Sat Aug 28 02:29:34 GMT 2000 B.C.E.',false],[-1999,8,28,2,29,34,'GMT',0,6], __LINE__], + + # collection + [['Tuesday, May 18, 1999 Published at 13:36 GMT 14:36 UK',false],[1999,5,18,13,36,nil,'GMT',0,2], __LINE__], # bbc.co.uk + [['July 20, 2000 Web posted at: 3:37 p.m. EDT (1937 GMT)',false],[2000,7,20,15,37,nil,'EDT',-4*3600,nil], __LINE__], # cnn.com + [['12:54 p.m. EDT, September 11, 2006',false],[2006,9,11,12,54,nil,'EDT',-4*3600,nil], __LINE__], # cnn.com + [['February 04, 2001 at 10:59 AM PST',false],[2001,2,4,10,59,nil,'PST',-8*3600,nil], __LINE__], # old amazon.com + [['Monday May 08, @01:55PM',false],[nil,5,8,13,55,nil,nil,nil,1], __LINE__], # slashdot.org + [['06.June 2005',false],[2005,6,6,nil,nil,nil,nil,nil,nil], __LINE__], # dhl.com + + # etc. + [['8:00 pm lt',false],[nil,nil,nil,20,0,nil,'lt',nil,nil], __LINE__], + [['4:00 AM, Jan. 12, 1990',false],[1990,1,12,4,0,nil,nil,nil,nil], __LINE__], + [['Jan. 12 4:00 AM 1990',false],[1990,1,12,4,0,nil,nil,nil,nil], __LINE__], + [['1990-01-12 04:00:00+00',false],[1990,1,12,4,0,0,'+00',0,nil], __LINE__], + [['1990-01-11 20:00:00-08',false],[1990,1,11,20,0,0,'-08',-8*3600,nil], __LINE__], + [['1990/01/12 04:00:00',false],[1990,1,12,4,0,0,nil,nil,nil], __LINE__], + [['Thu Jan 11 20:00:00 PST 1990',false],[1990,1,11,20,0,0,'PST',-8*3600,4], __LINE__], + [['Fri Jan 12 04:00:00 GMT 1990',false],[1990,1,12,4,0,0,'GMT',0,5], __LINE__], + [['Thu, 11 Jan 1990 20:00:00 -0800',false],[1990,1,11,20,0,0,'-0800',-8*3600,4], __LINE__], + [['12-January-1990, 04:00 WET',false],[1990,1,12,4,0,nil,'WET',0*3600,nil], __LINE__], + [['jan 2 3 am +4 5',false],[5,1,2,3,nil,nil,'+4',4*3600,nil], __LINE__], + [['jan 2 3 am +4 5',true],[2005,1,2,3,nil,nil,'+4',4*3600,nil], __LINE__], + [['fri1feb3bc4pm+5',false],[-2,2,1,16,nil,nil,'+5',5*3600,5], __LINE__], + [['fri1feb3bc4pm+5',true],[-2,2,1,16,nil,nil,'+5',5*3600,5], __LINE__], + [['03 feb 1st',false],[03,2,1,nil,nil,nil,nil,nil,nil], __LINE__], + + # apostrophe + [["July 4, '79",true],[1979,7,4,nil,nil,nil,nil,nil,nil], __LINE__], + [["4th July '79",true],[1979,7,4,nil,nil,nil,nil,nil,nil], __LINE__], + + # day of week + [['Sunday',false],[nil,nil,nil,nil,nil,nil,nil,nil,0], __LINE__], + [['Mon',false],[nil,nil,nil,nil,nil,nil,nil,nil,1], __LINE__], + [['Tue',false],[nil,nil,nil,nil,nil,nil,nil,nil,2], __LINE__], + [['Wed',false],[nil,nil,nil,nil,nil,nil,nil,nil,3], __LINE__], + [['Thurs',false],[nil,nil,nil,nil,nil,nil,nil,nil,4], __LINE__], + [['Friday',false],[nil,nil,nil,nil,nil,nil,nil,nil,5], __LINE__], + [['Sat.',false],[nil,nil,nil,nil,nil,nil,nil,nil,6], __LINE__], + [['sat.',false],[nil,nil,nil,nil,nil,nil,nil,nil,6], __LINE__], + [['SAT.',false],[nil,nil,nil,nil,nil,nil,nil,nil,6], __LINE__], + [['sAt.',false],[nil,nil,nil,nil,nil,nil,nil,nil,6], __LINE__], + + # time + [['09:55',false],[nil,nil,nil,9,55,nil,nil,nil,nil], __LINE__], + [['09:55:30',false],[nil,nil,nil,9,55,30,nil,nil,nil], __LINE__], + [['09:55:30am',false],[nil,nil,nil,9,55,30,nil,nil,nil], __LINE__], + [['09:55:30pm',false],[nil,nil,nil,21,55,30,nil,nil,nil], __LINE__], + [['09:55:30a.m.',false],[nil,nil,nil,9,55,30,nil,nil,nil], __LINE__], + [['09:55:30p.m.',false],[nil,nil,nil,21,55,30,nil,nil,nil], __LINE__], + [['09:55:30pm GMT',false],[nil,nil,nil,21,55,30,'GMT',0,nil], __LINE__], + [['09:55:30p.m. GMT',false],[nil,nil,nil,21,55,30,'GMT',0,nil], __LINE__], + [['09:55+0900',false],[nil,nil,nil,9,55,nil,'+0900',9*3600,nil], __LINE__], + [['09 AM',false],[nil,nil,nil,9,nil,nil,nil,nil,nil], __LINE__], + [['09am',false],[nil,nil,nil,9,nil,nil,nil,nil,nil], __LINE__], + [['09 A.M.',false],[nil,nil,nil,9,nil,nil,nil,nil,nil], __LINE__], + [['09 PM',false],[nil,nil,nil,21,nil,nil,nil,nil,nil], __LINE__], + [['09pm',false],[nil,nil,nil,21,nil,nil,nil,nil,nil], __LINE__], + [['09 P.M.',false],[nil,nil,nil,21,nil,nil,nil,nil,nil], __LINE__], + + [['9h22m23s',false],[nil,nil,nil,9,22,23,nil,nil,nil], __LINE__], + [['9h 22m 23s',false],[nil,nil,nil,9,22,23,nil,nil,nil], __LINE__], + [['9h22m',false],[nil,nil,nil,9,22,nil,nil,nil,nil], __LINE__], + [['9h 22m',false],[nil,nil,nil,9,22,nil,nil,nil,nil], __LINE__], + [['9h',false],[nil,nil,nil,9,nil,nil,nil,nil,nil], __LINE__], + [['9h 22m 23s am',false],[nil,nil,nil,9,22,23,nil,nil,nil], __LINE__], + [['9h 22m 23s pm',false],[nil,nil,nil,21,22,23,nil,nil,nil], __LINE__], + [['9h 22m am',false],[nil,nil,nil,9,22,nil,nil,nil,nil], __LINE__], + [['9h 22m pm',false],[nil,nil,nil,21,22,nil,nil,nil,nil], __LINE__], + [['9h am',false],[nil,nil,nil,9,nil,nil,nil,nil,nil], __LINE__], + [['9h pm',false],[nil,nil,nil,21,nil,nil,nil,nil,nil], __LINE__], + + [['00:00',false],[nil,nil,nil,0,0,nil,nil,nil,nil], __LINE__], + [['01:00',false],[nil,nil,nil,1,0,nil,nil,nil,nil], __LINE__], + [['11:00',false],[nil,nil,nil,11,0,nil,nil,nil,nil], __LINE__], + [['12:00',false],[nil,nil,nil,12,0,nil,nil,nil,nil], __LINE__], + [['13:00',false],[nil,nil,nil,13,0,nil,nil,nil,nil], __LINE__], + [['23:00',false],[nil,nil,nil,23,0,nil,nil,nil,nil], __LINE__], + [['24:00',false],[nil,nil,nil,24,0,nil,nil,nil,nil], __LINE__], + + [['00:00 AM',false],[nil,nil,nil,0,0,nil,nil,nil,nil], __LINE__], + [['12:00 AM',false],[nil,nil,nil,0,0,nil,nil,nil,nil], __LINE__], + [['01:00 AM',false],[nil,nil,nil,1,0,nil,nil,nil,nil], __LINE__], + [['11:00 AM',false],[nil,nil,nil,11,0,nil,nil,nil,nil], __LINE__], + [['00:00 PM',false],[nil,nil,nil,12,0,nil,nil,nil,nil], __LINE__], + [['12:00 PM',false],[nil,nil,nil,12,0,nil,nil,nil,nil], __LINE__], + [['01:00 PM',false],[nil,nil,nil,13,0,nil,nil,nil,nil], __LINE__], + [['11:00 PM',false],[nil,nil,nil,23,0,nil,nil,nil,nil], __LINE__], + + # pick up the rest + [['2000-01-02 1',false],[2000,1,2,1,nil,nil,nil,nil,nil], __LINE__], + [['2000-01-02 23',false],[2000,1,2,23,nil,nil,nil,nil,nil], __LINE__], + [['2000-01-02 24',false],[2000,1,2,24,nil,nil,nil,nil,nil], __LINE__], + [['1 03:04:05',false],[nil,nil,1,3,4,5,nil,nil,nil], __LINE__], + [['02 03:04:05',false],[nil,nil,2,3,4,5,nil,nil,nil], __LINE__], + [['31 03:04:05',false],[nil,nil,31,3,4,5,nil,nil,nil], __LINE__], + + # null, space + [['',false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\s",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\s" * 10, true],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\t",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\n",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\v",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\f",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\r",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["\t\n\v\f\r\s",false],[nil,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [["1999-05-23\t\n\v\f\r\s21:34:56",false],[1999,5,23,21,34,56,nil,nil,nil], __LINE__], + ].each do |x,y,l| + h = Date._parse(*x) + a = h.values_at(:year,:mon,:mday,:hour,:min,:sec,:zone,:offset,:wday) + if y[1] == -1 + a[1] = -1 + a[2] = h[:yday] + end + assert_equal(y, a, format('', l)) + end + end + + def test__parse_slash_exp + [ + # little + [['2/5/1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['02/05/1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['02/05/-1999',false],[-1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['05/02',false],[nil,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [[' 5/ 2',false],[nil,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [["2/5/'99",true],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['2/5/0099',false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['2/5/0099',true],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [['2/5 1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['2/5-1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['2/5--1999',false],[-1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + # big + [['99/5/2',false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['99/5/2',true],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [['1999/5/2',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['1999/05/02',false],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['-1999/05/02',false],[-1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [['0099/5/2',false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [['0099/5/2',true],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + + [["'99/5/2",false],[99,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + [["'99/5/2",true],[1999,5,2,nil,nil,nil,nil,nil,nil], __LINE__], + ].each do |x,y,l| + h = Date._parse(*x) + a = h.values_at(:year,:mon,:mday,:hour,:min,:sec,:zone,:offset,:wday) + if y[1] == -1 + a[1] = -1 + a[2] = h[:yday] + end + assert_equal(y, a, format('', l)) + end + end + + def test__parse__2 + h = Date._parse('22:45:59.5') + assert_equal([22, 45, 59, 5.to_r/10**1], h.values_at(:hour, :min, :sec, :sec_fraction)) + h = Date._parse('22:45:59.05') + assert_equal([22, 45, 59, 5.to_r/10**2], h.values_at(:hour, :min, :sec, :sec_fraction)) + h = Date._parse('22:45:59.005') + assert_equal([22, 45, 59, 5.to_r/10**3], h.values_at(:hour, :min, :sec, :sec_fraction)) + h = Date._parse('22:45:59.0123') + assert_equal([22, 45, 59, 123.to_r/10**4], h.values_at(:hour, :min, :sec, :sec_fraction)) + + h = Date._parse('224559.5') + assert_equal([22, 45, 59, 5.to_r/10**1], h.values_at(:hour, :min, :sec, :sec_fraction)) + h = Date._parse('224559.05') + assert_equal([22, 45, 59, 5.to_r/10**2], h.values_at(:hour, :min, :sec, :sec_fraction)) + h = Date._parse('224559.005') + assert_equal([22, 45, 59, 5.to_r/10**3], h.values_at(:hour, :min, :sec, :sec_fraction)) + h = Date._parse('224559.0123') + assert_equal([22, 45, 59, 123.to_r/10**4], h.values_at(:hour, :min, :sec, :sec_fraction)) + + h = Date._parse('2006-w15-5') + assert_equal([2006, 15, 5], h.values_at(:cwyear, :cweek, :cwday)) + h = Date._parse('2006w155') + assert_equal([2006, 15, 5], h.values_at(:cwyear, :cweek, :cwday)) + h = Date._parse('06w155', false) + assert_equal([6, 15, 5], h.values_at(:cwyear, :cweek, :cwday)) + h = Date._parse('06w155', true) + assert_equal([2006, 15, 5], h.values_at(:cwyear, :cweek, :cwday)) + + h = Date._parse('2006-w15') + assert_equal([2006, 15, nil], h.values_at(:cwyear, :cweek, :cwday)) + h = Date._parse('2006w15') + assert_equal([2006, 15, nil], h.values_at(:cwyear, :cweek, :cwday)) + + h = Date._parse('-w15-5') + assert_equal([nil, 15, 5], h.values_at(:cwyear, :cweek, :cwday)) + h = Date._parse('-w155') + assert_equal([nil, 15, 5], h.values_at(:cwyear, :cweek, :cwday)) + + h = Date._parse('-w15') + assert_equal([nil, 15, nil], h.values_at(:cwyear, :cweek, :cwday)) + h = Date._parse('-w15') + assert_equal([nil, 15, nil], h.values_at(:cwyear, :cweek, :cwday)) + + h = Date._parse('-w-5') + assert_equal([nil, nil, 5], h.values_at(:cwyear, :cweek, :cwday)) + + h = Date._parse('--11-29') + assert_equal([nil, 11, 29], h.values_at(:year, :mon, :mday)) + h = Date._parse('--1129') + assert_equal([nil, 11, 29], h.values_at(:year, :mon, :mday)) + h = Date._parse('--11') + assert_equal([nil, 11, nil], h.values_at(:year, :mon, :mday)) + h = Date._parse('---29') + assert_equal([nil, nil, 29], h.values_at(:year, :mon, :mday)) + h = Date._parse('-333') + assert_equal([nil, 333], h.values_at(:year, :yday)) + + h = Date._parse('2006-333') + assert_equal([2006, 333], h.values_at(:year, :yday)) + h = Date._parse('2006333') + assert_equal([2006, 333], h.values_at(:year, :yday)) + h = Date._parse('06333', false) + assert_equal([6, 333], h.values_at(:year, :yday)) + h = Date._parse('06333', true) + assert_equal([2006, 333], h.values_at(:year, :yday)) + h = Date._parse('333') + assert_equal([nil, 333], h.values_at(:year, :yday)) + + h = Date._parse('') + assert_equal({}, h) + end + + def test_parse + assert_equal(Date.new, Date.parse) + assert_equal(Date.new(2002,3,14), Date.parse('2002-03-14')) + + assert_equal(DateTime.new(2002,3,14,11,22,33, 0), + DateTime.parse('2002-03-14T11:22:33Z')) + assert_equal(DateTime.new(2002,3,14,11,22,33, 9.to_r/24), + DateTime.parse('2002-03-14T11:22:33+09:00')) + assert_equal(DateTime.new(2002,3,14,11,22,33, -9.to_r/24), + DateTime.parse('2002-03-14T11:22:33-09:00')) + assert_equal(DateTime.new(2002,3,14,11,22,33, -9.to_r/24) + 123456789.to_r/1000000000/86400, + DateTime.parse('2002-03-14T11:22:33.123456789-09:00')) + end + + def test_parse__2 + d1 = DateTime.parse('2004-03-13T22:45:59.5') + d2 = DateTime.parse('2004-03-13T22:45:59') + assert_equal(d2 + 5.to_r/10**1/86400, d1) + d1 = DateTime.parse('2004-03-13T22:45:59.05') + d2 = DateTime.parse('2004-03-13T22:45:59') + assert_equal(d2 + 5.to_r/10**2/86400, d1) + d1 = DateTime.parse('2004-03-13T22:45:59.005') + d2 = DateTime.parse('2004-03-13T22:45:59') + assert_equal(d2 + 5.to_r/10**3/86400, d1) + d1 = DateTime.parse('2004-03-13T22:45:59.0123') + d2 = DateTime.parse('2004-03-13T22:45:59') + assert_equal(d2 + 123.to_r/10**4/86400, d1) + d1 = DateTime.parse('2004-03-13T22:45:59.5') + d1 += 1.to_r/2/86400 + d2 = DateTime.parse('2004-03-13T22:46:00') + assert_equal(d2, d1) + end + + def test__parse_odd_offset + h = DateTime._parse('2001-02-03T04:05:06+1') + assert_equal(3600, h[:offset]) + h = DateTime._parse('2001-02-03T04:05:06+123') + assert_equal(4980, h[:offset]) + h = DateTime._parse('2001-02-03T04:05:06+12345') + assert_equal(5025, h[:offset]) + end + + require 'time' + + def test_parse__time + methods = [:to_s, :asctime, :iso8601, :rfc2822, :httpdate, :xmlschema] + + t = Time.utc(2001,2,3,4,5,6) + methods.each do |m| + d = DateTime.parse(t.__send__(m)) + assert_equal([2001, 2, 3, 4, 5, 6], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec], + [m, t.__send__(m)].inspect) + end + + t = Time.mktime(2001,2,3,4,5,6) + methods.each do |m| + next if m == :httpdate + d = DateTime.parse(t.__send__(m)) + assert_equal([2001, 2, 3, 4, 5, 6], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec], + [m, t.__send__(m)].inspect) + end + end + + def test_parse__comp + n = DateTime.now + + d = DateTime.parse('073') + assert_equal([n.year, 73, 0, 0, 0], + [d.year, d.yday, d.hour, d.min, d.sec]) + d = DateTime.parse('13') + assert_equal([n.year, n.mon, 13, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.parse('Mar 13') + assert_equal([n.year, 3, 13, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.parse('Mar 2004') + assert_equal([2004, 3, 1, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.parse('23:55') + assert_equal([n.year, n.mon, n.mday, 23, 55, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.parse('23:55:30') + assert_equal([n.year, n.mon, n.mday, 23, 55, 30], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.parse('Sun 23:55') + d2 = d - d.wday + assert_equal([d2.year, d2.mon, d2.mday, 23, 55, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.parse('Aug 23:55') + assert_equal([n.year, 8, 1, 23, 55, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + end + + def test_parse__d_to_s + d = Date.new(2002,3,14) + assert_equal(d, Date.parse(d.to_s)) + + d = DateTime.new(2002,3,14,11,22,33, 9.to_r/24) + assert_equal(d, DateTime.parse(d.to_s)) + end + + def test_parse_utf8 + h = DateTime._parse("Sun\u{3000}Aug 16 01:02:03 \u{65e5}\u{672c} 2009") + assert_equal(2009, h[:year]) + assert_equal(8, h[:mon]) + assert_equal(16, h[:mday]) + assert_equal(0, h[:wday]) + assert_equal(1, h[:hour]) + assert_equal(2, h[:min]) + assert_equal(3, h[:sec]) + assert_equal("\u{65e5}\u{672c}", h[:zone]) + end + + def test_parse__ex + assert_raise(ArgumentError) do + Date.parse('') + end + assert_raise(ArgumentError) do + DateTime.parse('') + end + assert_raise(ArgumentError) do + Date.parse('2001-02-29') + end + assert_raise(ArgumentError) do + DateTime.parse('2001-02-29T23:59:60') + end + assert_nothing_raised(ArgumentError) do + DateTime.parse('2001-03-01T23:59:60') + end + assert_raise(ArgumentError) do + DateTime.parse('2001-03-01T23:59:61') + end + assert_raise(ArgumentError) do + Date.parse('23:55') + end + end + + def test__iso8601 + h = Date._iso8601('01-02-03T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-02-03T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('--02-03T04:05:06Z') + assert_equal([nil, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('---03T04:05:06Z') + assert_equal([nil, nil, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('2001-02-03T04:05') + assert_equal([2001, 2, 3, 4, 5, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-02-03T04:05:06') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-02-03T04:05:06,07') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-02-03T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-02-03T04:05:06.07+01:00') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('010203T040506Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203T040506Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('--0203T040506Z') + assert_equal([nil, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('---03T040506Z') + assert_equal([nil, nil, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('010203T0405') + assert_equal([2001, 2, 3, 4, 5, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203T0405') + assert_equal([2001, 2, 3, 4, 5, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203T040506') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203T040506,07') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203T040506Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203T040506.07+0100') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('200102030405') + assert_equal([2001, 2, 3, 4, 5, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203040506') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203040506,07') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203040506Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('20010203040506.07+0100') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('01-023T04:05:06Z') + assert_equal([2001, 23, 4, 5, 6, 0], + h.values_at(:year, :yday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-023T04:05:06Z') + assert_equal([2001, 23, 4, 5, 6, 0], + h.values_at(:year, :yday, :hour, :min, :sec, :offset)) + h = Date._iso8601('-023T04:05:06Z') + assert_equal([nil, 23, 4, 5, 6, 0], + h.values_at(:year, :yday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('01023T040506Z') + assert_equal([2001, 23, 4, 5, 6, 0], + h.values_at(:year, :yday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001023T040506Z') + assert_equal([2001, 23, 4, 5, 6, 0], + h.values_at(:year, :yday, :hour, :min, :sec, :offset)) + h = Date._iso8601('-023T040506Z') + assert_equal([nil, 23, 4, 5, 6, 0], + h.values_at(:year, :yday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('01-w02-3T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001-w02-3T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + h = Date._iso8601('-w02-3T04:05:06Z') + assert_equal([nil, 2, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + h = Date._iso8601('-w-3T04:05:06Z') + assert_equal([nil, nil, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('01w023T040506Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + h = Date._iso8601('2001w023T040506Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + h = Date._iso8601('-w023T040506Z') + assert_equal([nil, 2, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + h = Date._iso8601('-w-3T040506Z') + assert_equal([nil, nil, 3, 4, 5, 6, 0], + h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('04:05') + assert_equal([nil, nil, nil, 4, 5, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('04:05:06') + assert_equal([nil, nil, nil, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('04:05:06,07') + assert_equal([nil, nil, nil, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('04:05:06Z') + assert_equal([nil, nil, nil, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('04:05:06.07+01:00') + assert_equal([nil, nil, nil, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('040506,07') + assert_equal([nil, nil, nil, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._iso8601('040506.07+0100') + assert_equal([nil, nil, nil, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._iso8601('') + assert_equal({}, h) + end + + def test__rfc3339 + h = Date._rfc3339('2001-02-03T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc3339('2001-02-03 04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc3339('2001-02-03T04:05:06.07+01:00') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._rfc3339('') + assert_equal({}, h) + end + + def test__xmlschema + h = Date._xmlschema('2001-02-03') + assert_equal([2001, 2, 3, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02-03Z') + assert_equal([2001, 2, 3, nil, nil, nil, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02-03+01:00') + assert_equal([2001, 2, 3, nil, nil, nil, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('2001-02-03T04:05:06') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02-03T04:05:06.07') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02-03T04:05:06.07Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02-03T04:05:06.07+01:00') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('04:05:06') + assert_equal([nil, nil, nil, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('04:05:06Z') + assert_equal([nil, nil, nil, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('04:05:06+01:00') + assert_equal([nil, nil, nil, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('2001-02') + assert_equal([2001, 2, nil, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02Z') + assert_equal([2001, 2, nil, nil, nil, nil, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02+01:00') + assert_equal([2001, 2, nil, nil, nil, nil, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-02-01:00') + assert_equal([2001, 2, nil, nil, nil, nil, -3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('2001') + assert_equal([2001, nil, nil, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001Z') + assert_equal([2001, nil, nil, nil, nil, nil, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001+01:00') + assert_equal([2001, nil, nil, nil, nil, nil, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('2001-01:00') + assert_equal([2001, nil, nil, nil, nil, nil, -3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('--02') + assert_equal([nil, 2, nil, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('--02Z') + assert_equal([nil, 2, nil, nil, nil, nil, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._xmlschema('--02+01:00') + assert_equal([nil, 2, nil, nil, nil, nil, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('92001-02-03T04:05:06.07+01:00') + assert_equal([92001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('-92001-02-03T04:05:06.07+01:00') + assert_equal([-92001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._xmlschema('') + assert_equal({}, h) + end + + def test__rfc2822 + h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 EST') + assert_equal([2001, 2, 3, 4, 5, 6, -5*3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 +0000') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 +0100') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._rfc2822('Sat, 03 Feb 50 04:05:06 +0100') + assert_equal([1950, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc2822('Sat, 03 Feb 49 04:05:06 +0100') + assert_equal([2049, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._rfc2822('Sat, 03 Feb 100 04:05:06 +0100') + assert_equal([2000, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h1 = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT') + h2 = Date._rfc822('Sat, 3 Feb 2001 04:05:06 UT') + assert_equal(h1, h2) + + h = Date._rfc2822('') + assert_equal({}, h) + end + + def test__httpdate + h = Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._httpdate('Saturday, 03-Feb-01 04:05:06 GMT') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._httpdate('Sat Feb 3 04:05:06 2001') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._httpdate('Sat Feb 03 04:05:06 2001') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._httpdate('') + assert_equal({}, h) + end + + def test__jisx0301 + h = Date._jisx0301('13.02.03') + assert_equal([2001, 2, 3, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('H13.02.03') + assert_equal([2001, 2, 3, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('S63.02.03') + assert_equal([1988, 2, 3, nil, nil, nil, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._jisx0301('H13.02.03T04:05:06') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('H13.02.03T04:05:06,07') + assert_equal([2001, 2, 3, 4, 5, 6, nil], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('H13.02.03T04:05:06Z') + assert_equal([2001, 2, 3, 4, 5, 6, 0], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + h = Date._jisx0301('H13.02.03T04:05:06.07+0100') + assert_equal([2001, 2, 3, 4, 5, 6, 3600], + h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset)) + + h = Date._jisx0301('') + assert_equal({}, h) + end + + def test_iso8601 + assert_instance_of(Date, Date.iso8601) + assert_instance_of(DateTime, DateTime.iso8601) + + d = Date.iso8601('2001-02-03', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.iso8601('2001-02-03T04:05:06+07:00', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) + end + + def test_rfc3339 + assert_instance_of(Date, Date.rfc3339) + assert_instance_of(DateTime, DateTime.rfc3339) + + d = Date.rfc3339('2001-02-03T04:05:06+07:00', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.rfc3339('2001-02-03T04:05:06+07:00', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) + end + + def test_xmlschema + assert_instance_of(Date, Date.xmlschema) + assert_instance_of(DateTime, DateTime.xmlschema) + + d = Date.xmlschema('2001-02-03', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.xmlschema('2001-02-03T04:05:06+07:00', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) + end + + def test_rfc2822 + assert_instance_of(Date, Date.rfc2822) + assert_instance_of(DateTime, DateTime.rfc2822) + assert_instance_of(Date, Date.rfc822) + assert_instance_of(DateTime, DateTime.rfc822) + + d = Date.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + d = Date.rfc2822('3 Feb 2001 04:05:06 +0700', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) + d = DateTime.rfc2822('3 Feb 2001 04:05:06 +0700', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) + end + + def test_httpdate + assert_instance_of(Date, Date.httpdate) + assert_instance_of(DateTime, DateTime.httpdate) + + d = Date.httpdate('Sat, 03 Feb 2001 04:05:06 GMT', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+00:00'), d) + assert_equal(Date::ITALY + 10, d.start) + end + + def test_jisx0301 + assert_instance_of(Date, Date.jisx0301) + assert_instance_of(DateTime, DateTime.jisx0301) + + d = Date.jisx0301('H13.02.03', Date::ITALY + 10) + assert_equal(Date.new(2001,2,3), d) + assert_equal(Date::ITALY + 10, d.start) + + d = DateTime.jisx0301('H13.02.03T04:05:06+07:00', Date::ITALY + 10) + assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d) + assert_equal(Date::ITALY + 10, d.start) + end + + def test_given_string + s = '2001-02-03T04:05:06Z' + s0 = s.dup + + assert_not_equal({}, Date._parse(s)) + assert_equal(s0, s) + + assert_not_equal({}, Date._iso8601(s)) + assert_equal(s0, s) + + assert_not_equal({}, Date._rfc3339(s)) + assert_equal(s0, s) + + assert_not_equal({}, Date._xmlschema(s)) + assert_equal(s0, s) + + s = 'Sat, 3 Feb 2001 04:05:06 UT' + s0 = s.dup + assert_not_equal({}, Date._rfc2822(s)) + assert_equal(s0, s) + assert_not_equal({}, Date._rfc822(s)) + assert_equal(s0, s) + + s = 'Sat, 03 Feb 2001 04:05:06 GMT' + s0 = s.dup + assert_not_equal({}, Date._httpdate(s)) + assert_equal(s0, s) + + s = 'H13.02.03T04:05:06,07Z' + s0 = s.dup + assert_not_equal({}, Date._jisx0301(s)) + assert_equal(s0, s) + end + +end diff --git a/jni/ruby/test/date/test_date_strftime.rb b/jni/ruby/test/date/test_date_strftime.rb new file mode 100644 index 0000000..0ed9215 --- /dev/null +++ b/jni/ruby/test/date/test_date_strftime.rb @@ -0,0 +1,422 @@ +require 'test/unit' +require 'date' + +class TestDateStrftime < Test::Unit::TestCase + + STRFTIME_2001_02_03 = { + '%A'=>['Saturday',{:wday=>6}], + '%a'=>['Sat',{:wday=>6}], + '%B'=>['February',{:mon=>2}], + '%b'=>['Feb',{:mon=>2}], + '%c'=>['Sat Feb 3 00:00:00 2001', + {:wday=>6,:mon=>2,:mday=>3,:hour=>0,:min=>0,:sec=>0,:year=>2001}], + '%d'=>['03',{:mday=>3}], + '%e'=>[' 3',{:mday=>3}], + '%H'=>['00',{:hour=>0}], + '%I'=>['12',{:hour=>0}], + '%j'=>['034',{:yday=>34}], + '%M'=>['00',{:min=>0}], + '%m'=>['02',{:mon=>2}], + '%p'=>['AM',{}], + '%S'=>['00',{:sec=>0}], + '%U'=>['04',{:wnum0=>4}], + '%W'=>['05',{:wnum1=>5}], + '%X'=>['00:00:00',{:hour=>0,:min=>0,:sec=>0}], + '%x'=>['02/03/01',{:mon=>2,:mday=>3,:year=>2001}], + '%Y'=>['2001',{:year=>2001}], + '%y'=>['01',{:year=>2001}], + '%Z'=>['+00:00',{:zone=>'+00:00',:offset=>0}], + '%%'=>['%',{}], + '%C'=>['20',{}], + '%D'=>['02/03/01',{:mon=>2,:mday=>3,:year=>2001}], + '%F'=>['2001-02-03',{:year=>2001,:mon=>2,:mday=>3}], + '%G'=>['2001',{:cwyear=>2001}], + '%g'=>['01',{:cwyear=>2001}], + '%h'=>['Feb',{:mon=>2}], + '%k'=>[' 0',{:hour=>0}], + '%L'=>['000',{:sec_fraction=>0}], + '%l'=>['12',{:hour=>0}], + '%N'=>['000000000',{:sec_fraction=>0}], + '%n'=>["\n",{}], + '%P'=>['am',{}], + '%Q'=>['981158400000',{:seconds=>981158400.to_r}], + '%R'=>['00:00',{:hour=>0,:min=>0}], + '%r'=>['12:00:00 AM',{:hour=>0,:min=>0,:sec=>0}], + '%s'=>['981158400',{:seconds=>981158400}], + '%T'=>['00:00:00',{:hour=>0,:min=>0,:sec=>0}], + '%t'=>["\t",{}], + '%u'=>['6',{:cwday=>6}], + '%V'=>['05',{:cweek=>5}], + '%v'=>[' 3-Feb-2001',{:mday=>3,:mon=>2,:year=>2001}], + '%z'=>['+0000',{:zone=>'+0000',:offset=>0}], + '%+'=>['Sat Feb 3 00:00:00 +00:00 2001', + {:wday=>6,:mon=>2,:mday=>3, + :hour=>0,:min=>0,:sec=>0,:zone=>'+00:00',:offset=>0,:year=>2001}], + } + + STRFTIME_2001_02_03_CVS19 = { + } + + STRFTIME_2001_02_03_GNUext = { + '%:z'=>['+00:00',{:zone=>'+00:00',:offset=>0}], + '%::z'=>['+00:00:00',{:zone=>'+00:00:00',:offset=>0}], + '%:::z'=>['+00',{:zone=>'+00',:offset=>0}], + } + + STRFTIME_2001_02_03.update(STRFTIME_2001_02_03_CVS19) + STRFTIME_2001_02_03.update(STRFTIME_2001_02_03_GNUext) + + def test_strftime + d = Date.new(2001,2,3) + STRFTIME_2001_02_03.each do |f, s| + assert_equal(s[0], d.strftime(f), [f, s].inspect) + case f[-1,1] + when 'c', 'C', 'x', 'X', 'y', 'Y' + f2 = f.sub(/\A%/, '%E') + assert_equal(s[0], d.strftime(f2), [f2, s].inspect) + else + f2 = f.sub(/\A%/, '%E') + assert_equal(f2, d.strftime(f2), [f2, s].inspect) + end + case f[-1,1] + when 'd', 'e', 'H', 'k', 'I', 'l', 'm', 'M', 'S', 'u', 'U', 'V', 'w', 'W', 'y' + f2 = f.sub(/\A%/, '%O') + assert_equal(s[0], d.strftime(f2), [f2, s].inspect) + else + f2 = f.sub(/\A%/, '%O') + assert_equal(f2, d.strftime(f2), [f2, s].inspect) + end + end + end + + def test_strftime__2 + d = Date.new(2001,2,3) + assert_equal('2001-02-03', d.strftime) + + d = DateTime.new(2001,2,3) + assert_equal('2001-02-03T00:00:00+00:00', d.strftime) + + assert_equal('', d.strftime('')) + assert_equal("\s"*3, d.strftime("\s"*3)) + assert_equal("\tfoo\n\000\r", d.strftime("\tfoo\n\000\r")) + assert_equal("%\n", d.strftime("%\n")) # gnu + assert_equal('Saturday'*1024 + ',', d.strftime('%A'*1024 + ',')) + assert_equal('%%', d.strftime('%%%')) + assert_equal('Anton von Webern', d.strftime('Anton von Webern')) + + d = DateTime.new(2001,2,3, 1,2,3) + assert_equal('2001-02-03T01:02:03+00:00', d.strftime) + assert_equal('AM', d.strftime('%p')) + assert_equal('am', d.strftime('%P')) + d = DateTime.new(2001,2,3, 13,14,15) + assert_equal('2001-02-03T13:14:15+00:00', d.strftime) + assert_equal('PM', d.strftime('%p')) + assert_equal('pm', d.strftime('%P')) + end + + def test_strftime__3_1 + (Date.new(1970,1,1)..Date.new(2037,12,31)).each do |d| + t = Time.utc(d.year,d.mon,d.mday) + assert_equal(t.strftime('%U'), d.strftime('%U')) + assert_equal(t.strftime('%W'), d.strftime('%W')) + end + end + + def test_strftime__3_2 + s = Time.now.strftime('%G') + skip if s.empty? || s == '%G' + (Date.new(1970,1,1)..Date.new(2037,12,31)).each do |d| + t = Time.utc(d.year,d.mon,d.mday) + assert_equal(t.strftime('%G'), d.strftime('%G')) + assert_equal(t.strftime('%g'), d.strftime('%g')) + assert_equal(t.strftime('%V'), d.strftime('%V')) + assert_equal(t.strftime('%u'), d.strftime('%u')) + end + end + + def test_strftime__4 + s = '2006-08-08T23:15:33.123456789' + f = '%FT%T.%N' + d = DateTime.parse(s) + assert_equal(s, d.strftime(f)) + d = DateTime.strptime(s, f) + assert_equal(s, d.strftime(f)) + + s = '2006-08-08T23:15:33.123456789' + f = '%FT%T.%N' + d = DateTime.parse(s + '123456789') + assert_equal(s, d.strftime(f)) + d = DateTime.strptime(s + '123456789', f) + assert_equal(s, d.strftime(f)) + + si = '2006-08-08T23:15:33.9' + so = '2006-08-08T23:15:33.900000000' + f = '%FT%T.%N' + d = DateTime.parse(si) + assert_equal(so, d.strftime(f)) + d = DateTime.strptime(si, f) + assert_equal(so, d.strftime(f)) + + s = '2006-08-08T23:15:33.123' + f = '%FT%T.%L' + d = DateTime.parse(s) + assert_equal(s, d.strftime(f)) + d = DateTime.strptime(s, f) + assert_equal(s, d.strftime(f)) + + s = '2006-08-08T23:15:33.123' + f = '%FT%T.%L' + d = DateTime.parse(s + '123') + assert_equal(s, d.strftime(f)) + d = DateTime.strptime(s + '123', f) + assert_equal(s, d.strftime(f)) + + si = '2006-08-08T23:15:33.9' + so = '2006-08-08T23:15:33.900' + f = '%FT%T.%L' + d = DateTime.parse(si) + assert_equal(so, d.strftime(f)) + d = DateTime.strptime(si, f) + assert_equal(so, d.strftime(f)) + end + + def test_strftime__offset + s = '2006-08-08T23:15:33' + (-24..24).collect{|x| '%+.2d' % x}.each do |hh| + %w(00 30).each do |mm| + r = hh + mm + if r[-4,4] == '2430' + r = '+0000' + end + d = DateTime.parse(s + hh + mm) + assert_equal(r, d.strftime('%z')) + end + end + end + + def test_strftime_milli + s = '1970-01-01T00:00:00.123456789' + d = DateTime.parse(s) + assert_equal('123', d.strftime('%Q')) + s = '1970-01-02T02:03:04.123456789' + d = DateTime.parse(s) + assert_equal('93784123', d.strftime('%Q')) + end + + def test_strftime__minus + d = DateTime.new(1969, 12, 31, 23, 59, 59) + assert_equal('-1', d.strftime('%s')) + assert_equal('-1000', d.strftime('%Q')) + end + + def test_strftime__gnuext # coreutils + d = DateTime.new(2006,8,8,23,15,33,9.to_r/24) + + assert_equal('2006', d.strftime('%-Y')) + assert_equal('2006', d.strftime('%-5Y')) + assert_equal('02006', d.strftime('%5Y')) + assert_equal('2006', d.strftime('%_Y')) + assert_equal(' 2006', d.strftime('%_5Y')) + assert_equal('02006', d.strftime('%05Y')) + + assert_equal('8', d.strftime('%-d')) + assert_equal('8', d.strftime('%-3d')) + assert_equal('008', d.strftime('%3d')) + assert_equal(' 8', d.strftime('%_d')) + assert_equal(' 8', d.strftime('%_3d')) + assert_equal('008', d.strftime('%03d')) + + assert_equal('8', d.strftime('%-e')) + assert_equal('8', d.strftime('%-3e')) + assert_equal(' 8', d.strftime('%3e')) + assert_equal(' 8', d.strftime('%_e')) + assert_equal(' 8', d.strftime('%_3e')) + assert_equal('008', d.strftime('%03e')) + + assert_equal('Tuesday', d.strftime('%-10A')) + assert_equal(' Tuesday', d.strftime('%10A')) + assert_equal(' Tuesday', d.strftime('%_10A')) + assert_equal('000Tuesday', d.strftime('%010A')) + assert_equal('TUESDAY', d.strftime('%^A')) + assert_equal('TUESDAY', d.strftime('%#A')) + + assert_equal('Tue', d.strftime('%-6a')) + assert_equal(' Tue', d.strftime('%6a')) + assert_equal(' Tue', d.strftime('%_6a')) + assert_equal('000Tue', d.strftime('%06a')) + assert_equal('TUE', d.strftime('%^a')) + assert_equal('TUE', d.strftime('%#a')) + assert_equal(' TUE', d.strftime('%#6a')) + + assert_equal('August', d.strftime('%-10B')) + assert_equal(' August', d.strftime('%10B')) + assert_equal(' August', d.strftime('%_10B')) + assert_equal('0000August', d.strftime('%010B')) + assert_equal('AUGUST', d.strftime('%^B')) + assert_equal('AUGUST', d.strftime('%#B')) + + assert_equal('Aug', d.strftime('%-6b')) + assert_equal(' Aug', d.strftime('%6b')) + assert_equal(' Aug', d.strftime('%_6b')) + assert_equal('000Aug', d.strftime('%06b')) + assert_equal('AUG', d.strftime('%^b')) + assert_equal('AUG', d.strftime('%#b')) + assert_equal(' AUG', d.strftime('%#6b')) + + assert_equal('Aug', d.strftime('%-6h')) + assert_equal(' Aug', d.strftime('%6h')) + assert_equal(' Aug', d.strftime('%_6h')) + assert_equal('000Aug', d.strftime('%06h')) + assert_equal('AUG', d.strftime('%^h')) + assert_equal('AUG', d.strftime('%#h')) + assert_equal(' AUG', d.strftime('%#6h')) + + assert_equal('PM', d.strftime('%^p')) + assert_equal('pm', d.strftime('%#p')) + assert_equal('PM', d.strftime('%^P')) + assert_equal('PM', d.strftime('%#P')) + + assert_equal('+000900', d.strftime('%7z')) + assert_equal(' +900', d.strftime('%_7z')) + assert_equal('+09:00', d.strftime('%:z')) + assert_equal('+0009:00', d.strftime('%8:z')) + assert_equal(' +9:00', d.strftime('%_8:z')) + assert_equal('+09:00:00', d.strftime('%::z')) + assert_equal('+0009:00:00', d.strftime('%11::z')) + assert_equal(' +9:00:00', d.strftime('%_11::z')) + assert_equal('+09', d.strftime('%:::z')) + assert_equal('+0009', d.strftime('%5:::z')) + assert_equal(' +9', d.strftime('%_5:::z')) + assert_equal('+9', d.strftime('%-:::z')) + + d = DateTime.new(-200,8,8,23,15,33,9.to_r/24) + + assert_equal('-0200', d.strftime('%Y')) + assert_equal('-200', d.strftime('%-Y')) + assert_equal('-200', d.strftime('%-5Y')) + assert_equal('-0200', d.strftime('%5Y')) + assert_equal(' -200', d.strftime('%_Y')) + assert_equal(' -200', d.strftime('%_5Y')) + assert_equal('-0200', d.strftime('%05Y')) + + d = DateTime.new(-2000,8,8,23,15,33,9.to_r/24) + + assert_equal('-2000', d.strftime('%Y')) + assert_equal('-2000', d.strftime('%-Y')) + assert_equal('-2000', d.strftime('%-5Y')) + assert_equal('-2000', d.strftime('%5Y')) + assert_equal('-2000', d.strftime('%_Y')) + assert_equal('-2000', d.strftime('%_5Y')) + assert_equal('-2000', d.strftime('%05Y')) + end + + def test_strftime__gnuext_LN # coreutils + d = DateTime.parse('2008-11-25T00:11:22.0123456789') + assert_equal('012', d.strftime('%L')) + assert_equal('012', d.strftime('%0L')) + assert_equal('0', d.strftime('%1L')) + assert_equal('01', d.strftime('%2L')) + assert_equal('01234567890', d.strftime('%11L')) + assert_equal('01234567890', d.strftime('%011L')) + assert_equal('01234567890', d.strftime('%_11L')) + assert_equal('012345678', d.strftime('%N')) + assert_equal('012345678', d.strftime('%0N')) + assert_equal('0', d.strftime('%1N')) + assert_equal('01', d.strftime('%2N')) + assert_equal('01234567890', d.strftime('%11N')) + assert_equal('01234567890', d.strftime('%011N')) + assert_equal('01234567890', d.strftime('%_11N')) + end + + def test_strftime__gnuext_z # coreutils + d = DateTime.parse('2006-08-08T23:15:33+09:08:07') + assert_equal('+0908', d.strftime('%z')) + assert_equal('+09:08', d.strftime('%:z')) + assert_equal('+09:08:07', d.strftime('%::z')) + assert_equal('+09:08:07', d.strftime('%:::z')) + end + + def test_strftime__gnuext_complex + d = DateTime.parse('2001-02-03T04:05:06+09:00') + assert_equal('Sat Feb 3 04:05:06 2001', d.strftime('%-100c')) + assert_equal('Sat Feb 3 04:05:06 2001'.rjust(100), d.strftime('%100c')) + assert_equal('Sat Feb 3 04:05:06 2001'.rjust(100), d.strftime('%_100c')) + assert_equal('Sat Feb 3 04:05:06 2001'.rjust(100, '0'), d.strftime('%0100c')) + assert_equal('SAT FEB 3 04:05:06 2001', d.strftime('%^c')) + + assert_equal('Sat Feb 3 04:05:06 +09:00 2001', d.strftime('%-100+')) + assert_equal('Sat Feb 3 04:05:06 +09:00 2001'.rjust(100), d.strftime('%100+')) + assert_equal('Sat Feb 3 04:05:06 +09:00 2001'.rjust(100), d.strftime('%_100+')) + assert_equal('Sat Feb 3 04:05:06 +09:00 2001'.rjust(100, '0'), d.strftime('%0100+')) + assert_equal('SAT FEB 3 04:05:06 +09:00 2001', d.strftime('%^+')) + end + + def test__different_format + d = Date.new(2001,2,3) + + assert_equal('Sat Feb 3 00:00:00 2001', d.ctime) + assert_equal(d.ctime, d.asctime) + + assert_equal('2001-02-03', d.iso8601) + assert_equal(d.xmlschema, d.iso8601) + assert_equal('2001-02-03T00:00:00+00:00', d.rfc3339) + assert_equal('Sat, 3 Feb 2001 00:00:00 +0000', d.rfc2822) + assert_equal(d.rfc822, d.rfc2822) + assert_equal('Sat, 03 Feb 2001 00:00:00 GMT', d.httpdate) + assert_equal('H13.02.03', d.jisx0301) + + d = DateTime.new(2001,2,3) + + assert_equal('Sat Feb 3 00:00:00 2001', d.ctime) + assert_equal(d.ctime, d.asctime) + + assert_equal('2001-02-03T00:00:00+00:00', d.iso8601) + assert_equal(d.rfc3339, d.iso8601) + assert_equal(d.xmlschema, d.iso8601) + assert_equal('Sat, 3 Feb 2001 00:00:00 +0000', d.rfc2822) + assert_equal(d.rfc822, d.rfc2822) + assert_equal('Sat, 03 Feb 2001 00:00:00 GMT', d.httpdate) + assert_equal('H13.02.03T00:00:00+00:00', d.jisx0301) + + d2 = DateTime.parse('2001-02-03T04:05:06.123456') + assert_equal('2001-02-03T04:05:06.123+00:00', d2.iso8601(3)) + assert_equal('2001-02-03T04:05:06.123+00:00', d2.rfc3339(3)) + assert_equal('H13.02.03T04:05:06.123+00:00', d2.jisx0301(3)) + assert_equal('2001-02-03T04:05:06.123+00:00', d2.iso8601(3.5)) + assert_equal('2001-02-03T04:05:06.123+00:00', d2.rfc3339(3.5)) + assert_equal('H13.02.03T04:05:06.123+00:00', d2.jisx0301(3.5)) + assert_equal('2001-02-03T04:05:06.123456000+00:00', d2.iso8601(9)) + assert_equal('2001-02-03T04:05:06.123456000+00:00', d2.rfc3339(9)) + assert_equal('H13.02.03T04:05:06.123456000+00:00', d2.jisx0301(9)) + assert_equal('2001-02-03T04:05:06.123456000+00:00', d2.iso8601(9.9)) + assert_equal('2001-02-03T04:05:06.123456000+00:00', d2.rfc3339(9.9)) + assert_equal('H13.02.03T04:05:06.123456000+00:00', d2.jisx0301(9.9)) + + assert_equal('1800-01-01T00:00:00+00:00', DateTime.new(1800).jisx0301) + + assert_equal('1868-01-25', Date.parse('1868-01-25').jisx0301) + assert_equal('1872-12-31', Date.parse('1872-12-31').jisx0301) + + assert_equal('M06.01.01', Date.parse('1873-01-01').jisx0301) + assert_equal('M45.07.29', Date.parse('1912-07-29').jisx0301) + assert_equal('T01.07.30', Date.parse('1912-07-30').jisx0301) + assert_equal('T15.12.24', Date.parse('1926-12-24').jisx0301) + assert_equal('S01.12.25', Date.parse('1926-12-25').jisx0301) + assert_equal('S64.01.07', Date.parse('1989-01-07').jisx0301) + assert_equal('H01.01.08', Date.parse('1989-01-08').jisx0301) + assert_equal('H18.09.01', Date.parse('2006-09-01').jisx0301) + + %w(M06.01.01 + M45.07.29 + T01.07.30 + T15.12.24 + S01.12.25 + S64.01.07 + H01.01.08 + H18.09.01).each do |s| + assert_equal(s, Date.parse(s).jisx0301) + end + + end + +end diff --git a/jni/ruby/test/date/test_date_strptime.rb b/jni/ruby/test/date/test_date_strptime.rb new file mode 100644 index 0000000..ae149bb --- /dev/null +++ b/jni/ruby/test/date/test_date_strptime.rb @@ -0,0 +1,512 @@ +require 'test/unit' +require 'date' + +class TestDateStrptime < Test::Unit::TestCase + + STRFTIME_2001_02_03 = { + '%A'=>['Saturday',{:wday=>6}], + '%a'=>['Sat',{:wday=>6}], + '%B'=>['February',{:mon=>2}], + '%b'=>['Feb',{:mon=>2}], + '%c'=>['Sat Feb 3 00:00:00 2001', + {:wday=>6,:mon=>2,:mday=>3,:hour=>0,:min=>0,:sec=>0,:year=>2001}], + '%d'=>['03',{:mday=>3}], + '%e'=>[' 3',{:mday=>3}], + '%H'=>['00',{:hour=>0}], + '%I'=>['12',{:hour=>0}], + '%j'=>['034',{:yday=>34}], + '%M'=>['00',{:min=>0}], + '%m'=>['02',{:mon=>2}], + '%p'=>['AM',{}], + '%S'=>['00',{:sec=>0}], + '%U'=>['04',{:wnum0=>4}], + '%W'=>['05',{:wnum1=>5}], + '%X'=>['00:00:00',{:hour=>0,:min=>0,:sec=>0}], + '%x'=>['02/03/01',{:mon=>2,:mday=>3,:year=>2001}], + '%Y'=>['2001',{:year=>2001}], + '%y'=>['01',{:year=>2001}], + '%Z'=>['+00:00',{:zone=>'+00:00',:offset=>0}], + '%%'=>['%',{}], + '%C'=>['20',{}], + '%D'=>['02/03/01',{:mon=>2,:mday=>3,:year=>2001}], + '%F'=>['2001-02-03',{:year=>2001,:mon=>2,:mday=>3}], + '%G'=>['2001',{:cwyear=>2001}], + '%g'=>['01',{:cwyear=>2001}], + '%h'=>['Feb',{:mon=>2}], + '%k'=>[' 0',{:hour=>0}], + '%L'=>['000',{:sec_fraction=>0}], + '%l'=>['12',{:hour=>0}], + '%N'=>['000000000',{:sec_fraction=>0}], + '%n'=>["\n",{}], + '%P'=>['am',{}], + '%Q'=>['981158400000',{:seconds=>981158400.to_r}], + '%R'=>['00:00',{:hour=>0,:min=>0}], + '%r'=>['12:00:00 AM',{:hour=>0,:min=>0,:sec=>0}], + '%s'=>['981158400',{:seconds=>981158400}], + '%T'=>['00:00:00',{:hour=>0,:min=>0,:sec=>0}], + '%t'=>["\t",{}], + '%u'=>['6',{:cwday=>6}], + '%V'=>['05',{:cweek=>5}], + '%v'=>[' 3-Feb-2001',{:mday=>3,:mon=>2,:year=>2001}], + '%z'=>['+0000',{:zone=>'+0000',:offset=>0}], + '%+'=>['Sat Feb 3 00:00:00 +00:00 2001', + {:wday=>6,:mon=>2,:mday=>3, + :hour=>0,:min=>0,:sec=>0,:zone=>'+00:00',:offset=>0,:year=>2001}], + } + + STRFTIME_2001_02_03_CVS19 = { + } + + STRFTIME_2001_02_03_GNUext = { + '%:z'=>['+00:00',{:zone=>'+00:00',:offset=>0}], + '%::z'=>['+00:00:00',{:zone=>'+00:00:00',:offset=>0}], + '%:::z'=>['+00',{:zone=>'+00',:offset=>0}], + } + + STRFTIME_2001_02_03.update(STRFTIME_2001_02_03_CVS19) + STRFTIME_2001_02_03.update(STRFTIME_2001_02_03_GNUext) + + def test__strptime + STRFTIME_2001_02_03.each do |f, s| + if (f == '%I' and s[0] == '12') or + (f == '%l' and s[0] == '12') # hour w/o merid + s[1][:hour] = 12 + end + assert_equal(s[1], Date._strptime(s[0], f), [f, s].inspect) + case f[-1,1] + when 'c', 'C', 'x', 'X', 'y', 'Y' + f2 = f.sub(/\A%/, '%E') + assert_equal(s[1], Date._strptime(s[0], f2), [f2, s].inspect) + else + f2 = f.sub(/\A%/, '%E') + assert_equal(nil, Date._strptime(s[0], f2), [f2, s].inspect) + assert_equal({}, Date._strptime(f2, f2), [f2, s].inspect) + end + case f[-1,1] + when 'd', 'e', 'H', 'I', 'm', 'M', 'S', 'u', 'U', 'V', 'w', 'W', 'y' + f2 = f.sub(/\A%/, '%O') + assert_equal(s[1], Date._strptime(s[0], f2), [f2, s].inspect) + else + f2 = f.sub(/\A%/, '%O') + assert_equal(nil, Date._strptime(s[0], f2), [f2, s].inspect) + assert_equal({}, Date._strptime(f2, f2), [f2, s].inspect) + end + end + end + + def test__strptime__2 + h = Date._strptime('2001-02-03') + assert_equal([2001,2,3], h.values_at(:year,:mon,:mday)) + + h = DateTime._strptime('2001-02-03T12:13:14Z') + assert_equal([2001,2,3,12,13,14], + h.values_at(:year,:mon,:mday,:hour,:min,:sec)) + + assert_equal({}, Date._strptime('', '')) + assert_equal({:leftover=>"\s"*3}, Date._strptime("\s"*3, '')) + assert_equal({:leftover=>'x'}, Date._strptime("\nx", "\n")) + assert_equal({}, Date._strptime('', "\s"*3)) + assert_equal({}, Date._strptime("\s"*3, "\s"*3)) + assert_equal({}, Date._strptime("\tfoo\n\000\r", "\tfoo\n\000\r")) + assert_equal({}, Date._strptime("foo\n\nbar", "foo\sbar")) + assert_equal({}, Date._strptime("%\n", "%\n")) # gnu + assert_equal({}, Date._strptime('%%', '%%%')) + assert_equal({:wday=>6}, Date._strptime('Saturday'*1024 + ',', '%A'*1024 + ',')) + assert_equal({:wday=>6}, Date._strptime('Saturday'*1024 + ',', '%a'*1024 + ',')) + assert_equal({}, Date._strptime('Anton von Webern', 'Anton von Webern')) + end + + def test__strptime__3 + [ + # iso8601 + [['2001-02-03', '%Y-%m-%d'], [2001,2,3,nil,nil,nil,nil,nil,nil], __LINE__], + [['2001-02-03T23:59:60', '%Y-%m-%dT%H:%M:%S'], [2001,2,3,23,59,60,nil,nil,nil], __LINE__], + [['2001-02-03T23:59:60+09:00', '%Y-%m-%dT%H:%M:%S%Z'], [2001,2,3,23,59,60,'+09:00',9*3600,nil], __LINE__], + [['-2001-02-03T23:59:60+09:00', '%Y-%m-%dT%H:%M:%S%Z'], [-2001,2,3,23,59,60,'+09:00',9*3600,nil], __LINE__], + [['+012345-02-03T23:59:60+09:00', '%Y-%m-%dT%H:%M:%S%Z'], [12345,2,3,23,59,60,'+09:00',9*3600,nil], __LINE__], + [['-012345-02-03T23:59:60+09:00', '%Y-%m-%dT%H:%M:%S%Z'], [-12345,2,3,23,59,60,'+09:00',9*3600,nil], __LINE__], + + # ctime(3), asctime(3) + [['Thu Jul 29 14:47:19 1999', '%c'], [1999,7,29,14,47,19,nil,nil,4], __LINE__], + [['Thu Jul 29 14:47:19 -1999', '%c'], [-1999,7,29,14,47,19,nil,nil,4], __LINE__], + + # date(1) + [['Thu Jul 29 16:39:41 EST 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'EST',-5*3600,4], __LINE__], + [['Thu Jul 29 16:39:41 MET DST 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'MET DST',2*3600,4], __LINE__], + [['Thu Jul 29 16:39:41 AMT 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'AMT',nil,4], __LINE__], + [['Thu Jul 29 16:39:41 AMT -1999', '%a %b %d %H:%M:%S %Z %Y'], [-1999,7,29,16,39,41,'AMT',nil,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT+09 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT+09',9*3600,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT+0908 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT+0908',9*3600+8*60,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT+090807 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT+090807',9*3600+8*60+7,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT-09 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT-09',-9*3600,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT-09:08 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT-09:08',-9*3600-8*60,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT-09:08:07 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT-09:08:07',-9*3600-8*60-7,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT-3.5 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT-3.5',-3*3600-30*60,4], __LINE__], + [['Thu Jul 29 16:39:41 GMT-3,5 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'GMT-3,5',-3*3600-30*60,4], __LINE__], + [['Thu Jul 29 16:39:41 Mountain Daylight Time 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'Mountain Daylight Time',-6*3600,4], __LINE__], + [['Thu Jul 29 16:39:41 E. Australia Standard Time 1999', '%a %b %d %H:%M:%S %Z %Y'], [1999,7,29,16,39,41,'E. Australia Standard Time',10*3600,4], __LINE__], + + # rfc822 + [['Thu, 29 Jul 1999 09:54:21 UT', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'UT',0,4], __LINE__], + [['Thu, 29 Jul 1999 09:54:21 GMT', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'GMT',0,4], __LINE__], + [['Thu, 29 Jul 1999 09:54:21 PDT', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'PDT',-7*3600,4], __LINE__], + [['Thu, 29 Jul 1999 09:54:21 z', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'z',0,4], __LINE__], + [['Thu, 29 Jul 1999 09:54:21 +0900', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'+0900',9*3600,4], __LINE__], + [['Thu, 29 Jul 1999 09:54:21 +0430', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'+0430',4*3600+30*60,4], __LINE__], + [['Thu, 29 Jul 1999 09:54:21 -0430', '%a, %d %b %Y %H:%M:%S %Z'], [1999,7,29,9,54,21,'-0430',-4*3600-30*60,4], __LINE__], + [['Thu, 29 Jul -1999 09:54:21 -0430', '%a, %d %b %Y %H:%M:%S %Z'], [-1999,7,29,9,54,21,'-0430',-4*3600-30*60,4], __LINE__], + + # etc + [['06-DEC-99', '%d-%b-%y'], [1999,12,6,nil,nil,nil,nil,nil,nil], __LINE__], + [['sUnDay oCtoBer 31 01', '%A %B %d %y'], [2001,10,31,nil,nil,nil,nil,nil,0], __LINE__], + [["October\t\n\v\f\r 15,\t\n\v\f\r99", '%B %d, %y'], [1999,10,15,nil,nil,nil,nil,nil,nil], __LINE__], + [["October\t\n\v\f\r 15,\t\n\v\f\r99", '%B%t%d,%n%y'], [1999,10,15,nil,nil,nil,nil,nil,nil], __LINE__], + + [['09:02:11 AM', '%I:%M:%S %p'], [nil,nil,nil,9,2,11,nil,nil,nil], __LINE__], + [['09:02:11 A.M.', '%I:%M:%S %p'], [nil,nil,nil,9,2,11,nil,nil,nil], __LINE__], + [['09:02:11 PM', '%I:%M:%S %p'], [nil,nil,nil,21,2,11,nil,nil,nil], __LINE__], + [['09:02:11 P.M.', '%I:%M:%S %p'], [nil,nil,nil,21,2,11,nil,nil,nil], __LINE__], + + [['12:33:44 AM', '%r'], [nil,nil,nil,0,33,44,nil,nil,nil], __LINE__], + [['01:33:44 AM', '%r'], [nil,nil,nil,1,33,44,nil,nil,nil], __LINE__], + [['11:33:44 AM', '%r'], [nil,nil,nil,11,33,44,nil,nil,nil], __LINE__], + [['12:33:44 PM', '%r'], [nil,nil,nil,12,33,44,nil,nil,nil], __LINE__], + [['01:33:44 PM', '%r'], [nil,nil,nil,13,33,44,nil,nil,nil], __LINE__], + [['11:33:44 PM', '%r'], [nil,nil,nil,23,33,44,nil,nil,nil], __LINE__], + + [['11:33:44 PM AMT', '%I:%M:%S %p %Z'], [nil,nil,nil,23,33,44,'AMT',nil,nil], __LINE__], + [['11:33:44 P.M. AMT', '%I:%M:%S %p %Z'], [nil,nil,nil,23,33,44,'AMT',nil,nil], __LINE__], + + [['fri1feb034pm+5', '%a%d%b%y%H%p%Z'], [2003,2,1,16,nil,nil,'+5',5*3600,5]] + ].each do |x, y| + h = Date._strptime(*x) + a = h.values_at(:year,:mon,:mday,:hour,:min,:sec,:zone,:offset,:wday) + if y[1] == -1 + a[1] = -1 + a[2] = h[:yday] + end + assert_equal(y, a, [x, y, a].inspect) + end + end + + def test__strptime__width + [ + [['99', '%y'], [1999,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['01', '%y'], [2001,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['19 99', '%C %y'], [1999,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['20 01', '%C %y'], [2001,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['30 99', '%C %y'], [3099,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['30 01', '%C %y'], [3001,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['1999', '%C%y'], [1999,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['2001', '%C%y'], [2001,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['3099', '%C%y'], [3099,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['3001', '%C%y'], [3001,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + + [['20060806', '%Y'], [20060806,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['20060806', "%Y\s"], [20060806,nil,nil,nil,nil,nil,nil,nil,nil], __LINE__], + [['20060806', '%Y%m%d'], [2006,8,6,nil,nil,nil,nil,nil,nil], __LINE__], + [['2006908906', '%Y9%m9%d'], [2006,8,6,nil,nil,nil,nil,nil,nil], __LINE__], + [['12006 08 06', '%Y %m %d'], [12006,8,6,nil,nil,nil,nil,nil,nil], __LINE__], + [['12006-08-06', '%Y-%m-%d'], [12006,8,6,nil,nil,nil,nil,nil,nil], __LINE__], + [['200608 6', '%Y%m%e'], [2006,8,6,nil,nil,nil,nil,nil,nil], __LINE__], + + [['2006333', '%Y%j'], [2006,-1,333,nil,nil,nil,nil,nil,nil], __LINE__], + [['20069333', '%Y9%j'], [2006,-1,333,nil,nil,nil,nil,nil,nil], __LINE__], + [['12006 333', '%Y %j'], [12006,-1,333,nil,nil,nil,nil,nil,nil], __LINE__], + [['12006-333', '%Y-%j'], [12006,-1,333,nil,nil,nil,nil,nil,nil], __LINE__], + + [['232425', '%H%M%S'], [nil,nil,nil,23,24,25,nil,nil,nil], __LINE__], + [['23924925', '%H9%M9%S'], [nil,nil,nil,23,24,25,nil,nil,nil], __LINE__], + [['23 24 25', '%H %M %S'], [nil,nil,nil,23,24,25,nil,nil,nil], __LINE__], + [['23:24:25', '%H:%M:%S'], [nil,nil,nil,23,24,25,nil,nil,nil], __LINE__], + [[' 32425', '%k%M%S'], [nil,nil,nil,3,24,25,nil,nil,nil], __LINE__], + [[' 32425', '%l%M%S'], [nil,nil,nil,3,24,25,nil,nil,nil], __LINE__], + + [['FriAug', '%a%b'], [nil,8,nil,nil,nil,nil,nil,nil,5], __LINE__], + [['FriAug', '%A%B'], [nil,8,nil,nil,nil,nil,nil,nil,5], __LINE__], + [['FridayAugust', '%A%B'], [nil,8,nil,nil,nil,nil,nil,nil,5], __LINE__], + [['FridayAugust', '%a%b'], [nil,8,nil,nil,nil,nil,nil,nil,5], __LINE__], + ].each do |x,y,l| + h = Date._strptime(*x) + a = (h || {}).values_at(:year,:mon,:mday,:hour,:min,:sec,:zone,:offset,:wday) + if y[1] == -1 + a[1] = -1 + a[2] = h[:yday] + end + assert_equal(y, a, format('', l)) + end + end + + def test__strptime__fail + assert_not_nil(Date._strptime('2001.', '%Y.')) + assert_not_nil(Date._strptime("2001.\s", '%Y.')) + assert_not_nil(Date._strptime('2001.', "%Y.\s")) + assert_not_nil(Date._strptime("2001.\s", "%Y.\s")) + + assert_nil(Date._strptime('2001', '%Y.')) + assert_nil(Date._strptime("2001\s", '%Y.')) + assert_nil(Date._strptime('2001', "%Y.\s")) + assert_nil(Date._strptime("2001\s", "%Y.\s")) + + assert_nil(Date._strptime('2001-13-31', '%Y-%m-%d')) + assert_nil(Date._strptime('2001-12-00', '%Y-%m-%d')) + assert_nil(Date._strptime('2001-12-32', '%Y-%m-%d')) + assert_nil(Date._strptime('2001-12-00', '%Y-%m-%e')) + assert_nil(Date._strptime('2001-12-32', '%Y-%m-%e')) + assert_nil(Date._strptime('2001-12-31', '%y-%m-%d')) + + assert_nil(Date._strptime('2004-000', '%Y-%j')) + assert_nil(Date._strptime('2004-367', '%Y-%j')) + assert_nil(Date._strptime('2004-366', '%y-%j')) + + assert_not_nil(Date._strptime('24:59:59', '%H:%M:%S')) + assert_not_nil(Date._strptime('24:59:59', '%k:%M:%S')) + assert_not_nil(Date._strptime('24:59:60', '%H:%M:%S')) + assert_not_nil(Date._strptime('24:59:60', '%k:%M:%S')) + + assert_nil(Date._strptime('24:60:59', '%H:%M:%S')) + assert_nil(Date._strptime('24:60:59', '%k:%M:%S')) + assert_nil(Date._strptime('24:59:61', '%H:%M:%S')) + assert_nil(Date._strptime('24:59:61', '%k:%M:%S')) + assert_nil(Date._strptime('00:59:59', '%I:%M:%S')) + assert_nil(Date._strptime('13:59:59', '%I:%M:%S')) + assert_nil(Date._strptime('00:59:59', '%l:%M:%S')) + assert_nil(Date._strptime('13:59:59', '%l:%M:%S')) + + assert_not_nil(Date._strptime('0', '%U')) + assert_nil(Date._strptime('54', '%U')) + assert_not_nil(Date._strptime('0', '%W')) + assert_nil(Date._strptime('54', '%W')) + assert_nil(Date._strptime('0', '%V')) + assert_nil(Date._strptime('54', '%V')) + assert_nil(Date._strptime('0', '%u')) + assert_not_nil(Date._strptime('7', '%u')) + assert_not_nil(Date._strptime('0', '%w')) + assert_nil(Date._strptime('7', '%w')) + + assert_nil(Date._strptime('Sanday', '%A')) + assert_nil(Date._strptime('Jenuary', '%B')) + assert_not_nil(Date._strptime('Sundai', '%A')) + assert_not_nil(Date._strptime('Januari', '%B')) + assert_nil(Date._strptime('Sundai,', '%A,')) + assert_nil(Date._strptime('Januari,', '%B,')) + end + + def test_strptime + assert_equal(Date.new, Date.strptime) + d = Date.new(2002,3,14) + assert_equal(d, Date.strptime(d.to_s)) + assert_equal(Date.new(2002,3,14), Date.strptime('2002-03-14')) + + d = DateTime.new(2002,3,14,11,22,33, 0) + assert_equal(d, DateTime.strptime(d.to_s)) + assert_equal(DateTime.new(2002,3,14,11,22,33, 0), + DateTime.strptime('2002-03-14T11:22:33Z')) + assert_equal(DateTime.new(2002,3,14,11,22,33, 0), + DateTime.strptime('2002-03-14T11:22:33Z', '%Y-%m-%dT%H:%M:%S%Z')) + assert_equal(DateTime.new(2002,3,14,11,22,33, 9.to_r/24), + DateTime.strptime('2002-03-14T11:22:33+09:00', '%Y-%m-%dT%H:%M:%S%Z')) + assert_equal(DateTime.new(2002,3,14,11,22,33, -9.to_r/24), + DateTime.strptime('2002-03-14T11:22:33-09:00', '%FT%T%Z')) + assert_equal(DateTime.new(2002,3,14,11,22,33, -9.to_r/24) + 123456789.to_r/1000000000/86400, + DateTime.strptime('2002-03-14T11:22:33.123456789-09:00', '%FT%T.%N%Z')) + end + + def test_strptime__2 + (Date.new(2006,6,1)..Date.new(2007,6,1)).each do |d| + [ + '%Y %m %d', + '%C %y %m %d', + + '%Y %j', + '%C %y %j', + + '%G %V %w', + '%G %V %u', + '%C %g %V %w', + '%C %g %V %u', + + '%Y %U %w', + '%Y %U %u', + '%Y %W %w', + '%Y %W %u', + '%C %y %U %w', + '%C %y %U %u', + '%C %y %W %w', + '%C %y %W %u', + ].each do |fmt| + s = d.strftime(fmt) + d2 = Date.strptime(s, fmt) + assert_equal(d, d2, [fmt, d.to_s, d2.to_s].inspect) + end + + [ + '%Y %m %d %H %M %S', + '%Y %m %d %H %M %S %N', + '%C %y %m %d %H %M %S', + '%C %y %m %d %H %M %S %N', + + '%Y %j %H %M %S', + '%Y %j %H %M %S %N', + '%C %y %j %H %M %S', + '%C %y %j %H %M %S %N', + + '%s', + '%s %N', + '%Q', + '%Q %N', + ].each do |fmt| + s = d.strftime(fmt) + d2 = DateTime.strptime(s, fmt) + assert_equal(d, d2, [fmt, d.to_s, d2.to_s].inspect) + end + end + end + + def test_strptime__minus + d = DateTime.strptime('-1', '%s') + assert_equal([1969, 12, 31, 23, 59, 59], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.strptime('-86400', '%s') + assert_equal([1969, 12, 31, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('-999', '%Q') + assert_equal([1969, 12, 31, 23, 59, 59, 1.to_r/10**3], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.sec_fraction]) + d = DateTime.strptime('-1000', '%Q') + assert_equal([1969, 12, 31, 23, 59, 59, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.sec_fraction]) + end + + def test_strptime__comp + n = DateTime.now + + d = DateTime.strptime('073', '%j') + assert_equal([n.year, 73, 0, 0, 0], + [d.year, d.yday, d.hour, d.min, d.sec]) + d = DateTime.strptime('13', '%d') + assert_equal([n.year, n.mon, 13, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('Mar', '%b') + assert_equal([n.year, 3, 1, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.strptime('2004', '%Y') + assert_equal([2004, 1, 1, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('Mar 13', '%b %d') + assert_equal([n.year, 3, 13, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.strptime('Mar 2004', '%b %Y') + assert_equal([2004, 3, 1, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.strptime('23:55', '%H:%M') + assert_equal([n.year, n.mon, n.mday, 23, 55, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.strptime('23:55:30', '%H:%M:%S') + assert_equal([n.year, n.mon, n.mday, 23, 55, 30], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('Sun 23:55', '%a %H:%M') + d2 = d - d.wday + assert_equal([d2.year, d2.mon, d2.mday, 23, 55, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + d = DateTime.strptime('Aug 23:55', '%b %H:%M') + assert_equal([n.year, 8, 1, 23, 55, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('2004', '%G') + assert_equal([2004, 1, 1, 0, 0, 0], + [d.cwyear, d.cweek, d.cwday, d.hour, d.min, d.sec]) + d = DateTime.strptime('11', '%V') + assert_equal([n.cwyear, 11, 1, 0, 0, 0], + [d.cwyear, d.cweek, d.cwday, d.hour, d.min, d.sec]) + d = DateTime.strptime('6', '%u') + assert_equal([n.cwyear, n.cweek, 6, 0, 0, 0], + [d.cwyear, d.cweek, d.cwday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('11-6', '%V-%u') + assert_equal([n.cwyear, 11, 6, 0, 0, 0], + [d.cwyear, d.cweek, d.cwday, d.hour, d.min, d.sec]) + d = DateTime.strptime('2004-11', '%G-%V') + assert_equal([2004, 11, 1, 0, 0, 0], + [d.cwyear, d.cweek, d.cwday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('11-6', '%U-%w') + assert_equal([n.year, 11, 6, 0, 0, 0], + [d.year, d.strftime('%U').to_i, d.wday, d.hour, d.min, d.sec]) + d = DateTime.strptime('2004-11', '%Y-%U') + assert_equal([2004, 11, 0, 0, 0, 0], + [d.year, d.strftime('%U').to_i, d.wday, d.hour, d.min, d.sec]) + + d = DateTime.strptime('11-6', '%W-%w') + assert_equal([n.year, 11, 6, 0, 0, 0], + [d.year, d.strftime('%W').to_i, d.wday, d.hour, d.min, d.sec]) + d = DateTime.strptime('2004-11', '%Y-%W') + assert_equal([2004, 11, 1, 0, 0, 0], + [d.year, d.strftime('%W').to_i, d.wday, d.hour, d.min, d.sec]) + end + + def test_strptime__d_to_s + d = Date.new(2002,3,14) + assert_equal(d, Date.strptime(d.to_s)) + + d = DateTime.new(2002,3,14,11,22,33, 9.to_r/24) + assert_equal(d, DateTime.strptime(d.to_s)) + end + + def test_strptime__ex + assert_raise(ArgumentError) do + Date.strptime('') + end + assert_raise(ArgumentError) do + DateTime.strptime('') + end + assert_raise(ArgumentError) do + Date.strptime('2001-02-29', '%F') + end + assert_raise(ArgumentError) do + DateTime.strptime('2001-02-29T23:59:60', '%FT%T') + end + assert_nothing_raised(ArgumentError) do + DateTime.strptime('2001-03-01T23:59:60', '%FT%T') + end + assert_raise(ArgumentError) do + DateTime.strptime('2001-03-01T23:59:61', '%FT%T') + end + assert_raise(ArgumentError) do + Date.strptime('23:55', '%H:%M') + end + assert_raise(ArgumentError) do + Date.strptime('01-31-2011', '%m/%d/%Y') + end + end + + def test_given_string + s = '2001-02-03T04:05:06Z' + s0 = s.dup + + assert_not_equal({}, Date._strptime(s, '%FT%T%Z')) + assert_equal(s0, s) + end + + def test_sz + d = DateTime.strptime('0 -0200', '%s %z') + assert_equal([1969, 12, 31, 22, 0, 0], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(-2, 24), d.offset) + d = DateTime.strptime('9 +0200', '%s %z') + assert_equal([1970, 1, 1, 2, 0, 9], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(2, 24), d.offset) + + d = DateTime.strptime('0 -0200', '%Q %z') + assert_equal([1969, 12, 31, 22, 0, 0], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(-2, 24), d.offset) + d = DateTime.strptime('9000 +0200', '%Q %z') + assert_equal([1970, 1, 1, 2, 0, 9], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(2, 24), d.offset) + + end + +end diff --git a/jni/ruby/test/date/test_switch_hitter.rb b/jni/ruby/test/date/test_switch_hitter.rb new file mode 100644 index 0000000..08e2301 --- /dev/null +++ b/jni/ruby/test/date/test_switch_hitter.rb @@ -0,0 +1,664 @@ +require 'test/unit' +require 'date' + +class TestSH < Test::Unit::TestCase + + def test_new + [Date.new, + Date.civil, + DateTime.new, + DateTime.civil + ].each do |d| + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + end + + [Date.new(2001), + Date.civil(2001), + DateTime.new(2001), + DateTime.civil(2001) + ].each do |d| + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + end + + d = Date.new(2001, 2, 3) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = Date.new(2001, 2, Rational('3.5')) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = Date.new(2001,2, 3, Date::JULIAN) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + d = Date.new(2001,2, 3, Date::GREGORIAN) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + + d = Date.new(2001,-12, -31) + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + d = Date.new(2001,-12, -31, Date::JULIAN) + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + d = Date.new(2001,-12, -31, Date::GREGORIAN) + assert_equal([2001, 1, 1], [d.year, d.mon, d.mday]) + + d = DateTime.new(2001, 2, 3, 4, 5, 6) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, 2, 3, 4, 5, 6, 0) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, 2, 3, 4, 5, 6, Rational(9,24)) + assert_equal([2001, 2, 3, 4, 5, 6, Rational(9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, 2, 3, 4, 5, 6, 0.375) + assert_equal([2001, 2, 3, 4, 5, 6, Rational(9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, 2, 3, 4, 5, 6, '+09:00') + assert_equal([2001, 2, 3, 4, 5, 6, Rational(9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, 2, 3, 4, 5, 6, '-09:00') + assert_equal([2001, 2, 3, 4, 5, 6, Rational(-9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, -12, -31, -4, -5, -6, '-09:00') + assert_equal([2001, 1, 1, 20, 55, 54, Rational(-9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, -12, -31, -4, -5, -6, '-09:00', Date::JULIAN) + assert_equal([2001, 1, 1, 20, 55, 54, Rational(-9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001, -12, -31, -4, -5, -6, '-09:00', Date::GREGORIAN) + assert_equal([2001, 1, 1, 20, 55, 54, Rational(-9,24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_jd + d = Date.jd + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + d = Date.jd(0) + assert_equal([-4712, 1, 1], [d.year, d.mon, d.mday]) + d = Date.jd(2451944) + assert_equal([2001, 2, 3], [d.year, d.mon, d.mday]) + + d = DateTime.jd + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(0) + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(2451944) + assert_equal([2001, 2, 3, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(2451944, 4, 5, 6) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(2451944, 4, 5, 6, 0) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(2451944, 4, 5, 6, '+9:00') + assert_equal([2001, 2, 3, 4, 5, 6, Rational(9, 24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.jd(2451944, -4, -5, -6, '-9:00') + assert_equal([2001, 2, 3, 20, 55, 54, Rational(-9, 24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_ordinal + d = Date.ordinal + assert_equal([-4712, 1], [d.year, d.yday]) + d = Date.ordinal(-4712, 1) + assert_equal([-4712, 1], [d.year, d.yday]) + + d = Date.ordinal(2001, 2) + assert_equal([2001, 2], [d.year, d.yday]) + d = Date.ordinal(2001, 2, Date::JULIAN) + assert_equal([2001, 2], [d.year, d.yday]) + d = Date.ordinal(2001, 2, Date::GREGORIAN) + assert_equal([2001, 2], [d.year, d.yday]) + + d = Date.ordinal(2001, -2, Date::JULIAN) + assert_equal([2001, 364], [d.year, d.yday]) + d = Date.ordinal(2001, -2, Date::GREGORIAN) + assert_equal([2001, 364], [d.year, d.yday]) + + d = DateTime.ordinal + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(-4712, 1) + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(2001, 34) + assert_equal([2001, 2, 3, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(2001, 34, 4, 5, 6) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(2001, 34, 4, 5, 6, 0) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(2001, 34, 4, 5, 6, '+9:00') + assert_equal([2001, 2, 3, 4, 5, 6, Rational(9, 24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(2001, 34, -4, -5, -6, '-9:00') + assert_equal([2001, 2, 3, 20, 55, 54, Rational(-9, 24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_commercial + d = Date.commercial + assert_equal([-4712, 1, 1], [d.cwyear, d.cweek, d.cwday]) + d = Date.commercial(-4712, 1, 1) + assert_equal([-4712, 1, 1], [d.cwyear, d.cweek, d.cwday]) + + d = Date.commercial(2001, 2, 3) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + d = Date.commercial(2001, 2, 3, Date::JULIAN) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + d = Date.commercial(2001, 2, 3, Date::GREGORIAN) + assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday]) + + d = Date.commercial(2001, -2, -3) + assert_equal([2001, 51, 5], [d.cwyear, d.cweek, d.cwday]) + d = Date.commercial(2001, -2, -3, Date::JULIAN) + assert_equal([2001, 51, 5], [d.cwyear, d.cweek, d.cwday]) + d = Date.commercial(2001, -2, -3, Date::GREGORIAN) + assert_equal([2001, 51, 5], [d.cwyear, d.cweek, d.cwday]) + + d = DateTime.commercial + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(-4712, 1, 1) + assert_equal([-4712, 1, 1, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(2001, 5, 6) + assert_equal([2001, 2, 3, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(2001, 5, 6, 4, 5, 6) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(2001, 5, 6, 4, 5, 6, 0) + assert_equal([2001, 2, 3, 4, 5, 6, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(2001, 5, 6, 4, 5, 6, '+9:00') + assert_equal([2001, 2, 3, 4, 5, 6, Rational(9, 24)], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(2001, 5, 6, -4, -5, -6, '-9:00') + assert_equal([2001, 2, 3, 20, 55, 54, Rational(-9, 24)], + [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], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.ordinal(2001,33,24) + assert_equal([2001, 2, 3, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.new(2001,2,2,24) + assert_equal([2001, 2, 3, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + d = DateTime.commercial(2001,5,5,24) + assert_equal([2001, 2, 3, 0, 0, 0, 0], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset]) + end + + def test_zone + d = Date.new(2001, 2, 3) + assert_equal(Encoding::US_ASCII, d.send(:zone).encoding) + d = DateTime.new(2001, 2, 3) + assert_equal(Encoding::US_ASCII, d.send(:zone).encoding) + end + + def test_to_s + d = Date.new(2001, 2, 3) + assert_equal(Encoding::US_ASCII, d.to_s.encoding) + assert_equal(Encoding::US_ASCII, d.strftime.encoding) + d = DateTime.new(2001, 2, 3) + assert_equal(Encoding::US_ASCII, d.to_s.encoding) + assert_equal(Encoding::US_ASCII, d.strftime.encoding) + end + + def test_inspect + d = Date.new(2001, 2, 3) + assert_equal(Encoding::US_ASCII, d.inspect.encoding) + d = DateTime.new(2001, 2, 3) + assert_equal(Encoding::US_ASCII, d.inspect.encoding) + end + + def test_strftime + assert_raise(Errno::ERANGE) do + Date.today.strftime('%100000z') + end + assert_raise(Errno::ERANGE) do + Date.new(1 << 10000).strftime('%Y') + end + assert_equal('-3786825600', Date.new(1850).strftime('%s')) + assert_equal('-3786825600000', Date.new(1850).strftime('%Q')) + end + + def test_cmp + assert_equal(-1, Date.new(2001,2,3) <=> Date.new(2001,2,4)) + assert_equal(0, Date.new(2001,2,3) <=> Date.new(2001,2,3)) + assert_equal(1, Date.new(2001,2,3) <=> Date.new(2001,2,2)) + + assert_equal(-1, Date.new(2001,2,3) <=> 2451944.0) + assert_equal(-1, Date.new(2001,2,3) <=> 2451944) + assert_equal(0, Date.new(2001,2,3) <=> 2451943.5) + assert_equal(1, Date.new(2001,2,3) <=> 2451943.0) + assert_equal(1, Date.new(2001,2,3) <=> 2451943) + + assert_equal(-1, Date.new(2001,2,3) <=> Rational('4903888/2')) + assert_equal(0, Date.new(2001,2,3) <=> Rational('4903887/2')) + assert_equal(1, Date.new(2001,2,3) <=> Rational('4903886/2')) + + assert_equal(-1, Date.new(-4713,11,1,Date::GREGORIAN) <=> Date.new(-4713,12,1,Date::GREGORIAN)) + end + + def test_eqeqeq + assert_equal(false, Date.new(2001,2,3) === Date.new(2001,2,4)) + assert_equal(true, Date.new(2001,2,3) === Date.new(2001,2,3)) + assert_equal(false, Date.new(2001,2,3) === Date.new(2001,2,2)) + + assert_equal(true, Date.new(2001,2,3) === 2451944.0) + assert_equal(true, Date.new(2001,2,3) === 2451944) + assert_equal(false, Date.new(2001,2,3) === 2451943.5) + assert_equal(false, Date.new(2001,2,3) === 2451943.0) + assert_equal(false, Date.new(2001,2,3) === 2451943) + + assert_equal(true, Date.new(2001,2,3) === Rational('4903888/2')) + assert_equal(false, Date.new(2001,2,3) === Rational('4903887/2')) + assert_equal(false, Date.new(2001,2,3) === Rational('4903886/2')) + end + + def test_period + # -5000 + d = Date.new(-5000,1,1) + assert_equal([-5000, 1, 1, 5], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5001, 11, 22, 5], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.new(-5000,1,1,Date::JULIAN) + assert_equal([-5000, 1, 1, 5], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5001, 11, 22, 5], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.new(-5000,1,1,Date::GREGORIAN) + assert_equal([-5000, 1, 1, 3], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([-5000, 2, 10, 3], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(-105192) + assert_equal([-5000, 1, 1, 5], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5001, 11, 22, 5], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(-105192,Date::JULIAN) + assert_equal([-5000, 1, 1, 5], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5001, 11, 22, 5], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(-105152,Date::GREGORIAN) + assert_equal([-5000, 1, 1, 3], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([-5000, 2, 10, 3], [d2.year, d2.mon, d2.mday, d.wday]) + + # -5000000 + d = Date.new(-5_000_000,1,1) + assert_equal([-5_000_000, 1, 1, 3], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5_000_103, 4, 28, 3], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.new(-5_000_000,1,1,Date::JULIAN) + assert_equal([-5_000_000, 1, 1, 3], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5_000_103, 4, 28, 3], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.new(-5_000_000,1,1,Date::GREGORIAN) + assert_equal([-5_000_000, 1, 1, 6], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([-4_999_898, 9, 4, 6], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(-1824528942) + assert_equal([-5_000_000, 1, 1, 3], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5_000_103, 4, 28, 3], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(-1824528942,Date::JULIAN) + assert_equal([-5_000_000, 1, 1, 3], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([-5_000_103, 4, 28, 3], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(-1824491440,Date::GREGORIAN) + assert_equal([-5_000_000, 1, 1, 6], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([-4_999_898, 9, 4, 6], [d2.year, d2.mon, d2.mday, d.wday]) + + # 5000000 + d = Date.new(5_000_000,1,1) + assert_equal([5_000_000, 1, 1, 6], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([4_999_897, 5, 3, 6], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.new(5_000_000,1,1,Date::JULIAN) + assert_equal([5_000_000, 1, 1, 5], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([5_000_102, 9, 1, 5], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.new(5_000_000,1,1,Date::GREGORIAN) + assert_equal([5_000_000, 1, 1, 6], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([4_999_897, 5, 3, 6], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(1827933560) + assert_equal([5_000_000, 1, 1, 6], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([4_999_897, 5, 3, 6], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(1827971058,Date::JULIAN) + assert_equal([5_000_000, 1, 1, 5], [d.year, d.mon, d.mday, d.wday]) + d2 = d.gregorian + assert_equal([5_000_102, 9, 1, 5], [d2.year, d2.mon, d2.mday, d.wday]) + + d = Date.jd(1827933560,Date::GREGORIAN) + assert_equal([5_000_000, 1, 1, 6], [d.year, d.mon, d.mday, d.wday]) + d2 = d.julian + assert_equal([4_999_897, 5, 3, 6], [d2.year, d2.mon, d2.mday, d.wday]) + + # dt + d = DateTime.new(-123456789,2,3,4,5,6,0) + assert_equal([-123456789, 2, 3, 4, 5, 6, 1], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.wday]) + d2 = d.gregorian + assert_equal([-123459325, 12, 27, 4, 5, 6, 1], + [d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec, d.wday]) + + d = DateTime.new(123456789,2,3,4,5,6,0) + assert_equal([123456789, 2, 3, 4, 5, 6, 5], + [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.wday]) + d2 = d.julian + assert_equal([123454254, 1, 19, 4, 5, 6, 5], + [d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec, d.wday]) + end + + def period2_iter2(from, to, sg) + (from..to).each do |j| + d = Date.jd(j, sg) + d2 = Date.new(d.year, d.mon, d.mday, sg) + assert_equal(d2.jd, j) + assert_equal(d2.ajd, d.ajd) + assert_equal(d2.year, d.year) + + d = DateTime.jd(j, 12,0,0, '+12:00', sg) + d2 = DateTime.new(d.year, d.mon, d.mday, + d.hour, d.min, d.sec, d.offset, sg) + assert_equal(d2.jd, j) + assert_equal(d2.ajd, d.ajd) + assert_equal(d2.year, d.year) + end + end + + def period2_iter(from, to) + period2_iter2(from, to, Date::GREGORIAN) + period2_iter2(from, to, Date::ITALY) + period2_iter2(from, to, Date::ENGLAND) + period2_iter2(from, to, Date::JULIAN) + end + + def test_period2 + cm_period0 = 71149239 + cm_period = 0xfffffff.div(cm_period0) * cm_period0 + period2_iter(-cm_period * (1 << 64) - 3, -cm_period * (1 << 64) + 3) + period2_iter(-cm_period - 3, -cm_period + 3) + period2_iter(0 - 3, 0 + 3) + period2_iter(+cm_period - 3, +cm_period + 3) + period2_iter(+cm_period * (1 << 64) - 3, +cm_period * (1 << 64) + 3) + end + + def test_different_alignments + assert_equal(0, Date.jd(0) <=> Date.civil(-4713, 11, 24, Date::GREGORIAN)) + assert_equal(0, Date.jd(213447717) <=> Date.civil(579687, 11, 24)) + assert_equal(0, Date.jd(-213447717) <=> Date.civil(-589113, 11, 24, Date::GREGORIAN)) + + assert_equal(0, Date.jd(0) <=> DateTime.civil(-4713, 11, 24, 0, 0, 0, 0, Date::GREGORIAN)) + assert_equal(0, Date.jd(213447717) <=> DateTime.civil(579687, 11, 24)) + assert_equal(0, Date.jd(-213447717) <=> DateTime.civil(-589113, 11, 24, 0, 0, 0, 0, Date::GREGORIAN)) + + assert(Date.jd(0) == Date.civil(-4713, 11, 24, Date::GREGORIAN)) + assert(Date.jd(213447717) == Date.civil(579687, 11, 24)) + assert(Date.jd(-213447717) == Date.civil(-589113, 11, 24, Date::GREGORIAN)) + + assert(Date.jd(0) == DateTime.civil(-4713, 11, 24, 0, 0, 0, 0, Date::GREGORIAN)) + assert(Date.jd(213447717) == DateTime.civil(579687, 11, 24)) + assert(Date.jd(-213447717) == DateTime.civil(-589113, 11, 24, 0, 0, 0, 0, Date::GREGORIAN)) + + assert(Date.jd(0) === Date.civil(-4713, 11, 24, Date::GREGORIAN)) + assert(Date.jd(213447717) === Date.civil(579687, 11, 24)) + assert(Date.jd(-213447717) === Date.civil(-589113, 11, 24, Date::GREGORIAN)) + + assert(Date.jd(0) === DateTime.civil(-4713, 11, 24, 12, 0, 0, 0, Date::GREGORIAN)) + assert(Date.jd(213447717) === DateTime.civil(579687, 11, 24, 12)) + assert(Date.jd(-213447717) === DateTime.civil(-589113, 11, 24, 12, 0, 0, 0, Date::GREGORIAN)) + + a = Date.jd(0) + b = Date.civil(-4713, 11, 24, Date::GREGORIAN) + assert_equal(0, a <=> b) + + a = Date.civil(-4712, 1, 1, Date::JULIAN) + b = Date.civil(-4713, 11, 24, Date::GREGORIAN) + a.jd; b.jd + assert_equal(0, a <=> b) + + a = Date.jd(0) + b = Date.civil(-4713, 11, 24, Date::GREGORIAN) + assert(a == b) + + a = Date.civil(-4712, 1, 1, Date::JULIAN) + b = Date.civil(-4713, 11, 24, Date::GREGORIAN) + a.jd; b.jd + assert(a == b) + + a = Date.jd(0) + b = Date.civil(-4713, 11, 24, Date::GREGORIAN) + assert(a === b) + + a = Date.civil(-4712, 1, 1, Date::JULIAN) + b = Date.civil(-4713, 11, 24, Date::GREGORIAN) + a.jd; b.jd + assert(a === b) + end + + def test_marshal14 + s = "\x04\x03u:\x01\x04Date\x01\v\x04\x03[\x01\x02i\x03\xE8i%T" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(0, d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + end + + def test_marshal16 + s = "\x04\x06u:\tDate\x0F\x04\x06[\ai\x03\xE8i%T" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(0, d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + end + + def test_marshal18 + s = "\x04\bu:\tDateP\x04\b[\bo:\rRational\a:\x0F@numeratori\x03\xCF\xD3J:\x11@denominatori\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(0, d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + + s = "\x04\bu:\rDateTime`\x04\b[\bo:\rRational\a:\x0F@numeratorl+\b\xC9\xB0\x81\xBD\x02\x00:\x11@denominatori\x02\xC0\x12o;\x00\a;\x06i\b;\ai\ro:\x13Date::Infinity\x06:\a@di\xFA" + d = Marshal.load(s) + assert_equal(Rational(11769327817,4800), d.ajd) + assert_equal(Rational(9,24), d.offset) + assert_equal(Date::GREGORIAN, d.start) + end + + def test_marshal192 + s = "\x04\bU:\tDate[\bU:\rRational[\ai\x03\xCF\xD3Ji\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(Rational(0,24), d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + + s = "\x04\bU:\rDateTime[\bU:\rRational[\al+\b\xC9\xB0\x81\xBD\x02\x00i\x02\xC0\x12U;\x06[\ai\bi\ro:\x13Date::Infinity\x06:\a@di\xFA" + d = Marshal.load(s) + assert_equal(Rational(11769327817,4800), d.ajd) + assert_equal(Rational(9,24), d.offset) + assert_equal(Date::GREGORIAN, d.start) + end + + def test_taint + h = Date._strptime('15:43+09:00', '%R%z') + assert_equal(false, h[:zone].tainted?) + h = Date._strptime('15:43+09:00'.taint, '%R%z') + assert_equal(true, h[:zone].tainted?) + + h = Date._strptime('1;1/0', '%d') + assert_equal(false, h[:leftover].tainted?) + h = Date._strptime('1;1/0'.taint, '%d') + assert_equal(true, h[:leftover].tainted?) + + h = Date._parse('15:43+09:00') + assert_equal(false, h[:zone].tainted?) + h = Date._parse('15:43+09:00'.taint) + assert_equal(true, h[:zone].tainted?) + + s = Date.today.strftime('new 105') + assert_equal(false, s.tainted?) + s = Date.today.strftime('new 105'.taint) + assert_equal(true, s.tainted?) + s = Date.today.strftime("new \000 105".taint) + assert_equal(true, s.tainted?) + + s = DateTime.now.strftime('super $record') + assert_equal(false, s.tainted?) + s = DateTime.now.strftime('super $record'.taint) + assert_equal(true, s.tainted?) + end + + def test_enc + Date::MONTHNAMES.each do |s| + assert_equal(Encoding::US_ASCII, s.encoding) if s + end + Date::DAYNAMES.each do |s| + assert_equal(Encoding::US_ASCII, s.encoding) if s + end + Date::ABBR_MONTHNAMES.each do |s| + assert_equal(Encoding::US_ASCII, s.encoding) if s + end + Date::ABBR_DAYNAMES.each do |s| + assert_equal(Encoding::US_ASCII, s.encoding) if s + end + + h = Date._strptime('15:43+09:00'.force_encoding('euc-jp'), '%R%z') + assert_equal(Encoding::EUC_JP, h[:zone].encoding) + h = Date._strptime('15:43+09:00'.force_encoding('ascii-8bit'), '%R%z') + assert_equal(Encoding::ASCII_8BIT, h[:zone].encoding) + + h = Date._strptime('1;1/0'.force_encoding('euc-jp'), '%d') + assert_equal(Encoding::EUC_JP, h[:leftover].encoding) + h = Date._strptime('1;1/0'.force_encoding('ascii-8bit'), '%d') + assert_equal(Encoding::ASCII_8BIT, h[:leftover].encoding) + + h = Date._parse('15:43+09:00'.force_encoding('euc-jp')) + assert_equal(Encoding::EUC_JP, h[:zone].encoding) + h = Date._parse('15:43+09:00'.force_encoding('ascii-8bit')) + assert_equal(Encoding::ASCII_8BIT, h[:zone].encoding) + + s = Date.today.strftime('new 105'.force_encoding('euc-jp')) + assert_equal(Encoding::EUC_JP, s.encoding) + s = Date.today.strftime('new 105'.force_encoding('ascii-8bit')) + assert_equal(Encoding::ASCII_8BIT, s.encoding) + + s = DateTime.now.strftime('super $record'.force_encoding('euc-jp')) + assert_equal(Encoding::EUC_JP, s.encoding) + s = DateTime.now.strftime('super $record'.force_encoding('ascii-8bit')) + assert_equal(Encoding::ASCII_8BIT, s.encoding) + end + + def test_dup + d = Date.new(2001,2,3) + d2 = d.dup + assert_not_equal(d.object_id, d2.object_id) + assert_kind_of(Date, d2) + assert_equal(d, d2) + + d = DateTime.new(2001,2,3) + d2 = d.dup + assert_not_equal(d.object_id, d2.object_id) + assert_kind_of(DateTime, d2) + assert_equal(d, d2) + end + + def test_base + skip unless defined?(Date.test_all) + assert_equal(true, Date.test_all) + end + +end -- cgit v1.2.3-70-g09d2