date_core.c: moved some methods to DateTime

* ext/date/date_core.c (Init_date_core): moved methods which make
  sense only for DateTime to that class, instead of defining
  private methods in Date and making them public in DateTime.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-12-11 04:35:13 +00:00
Родитель 73400c01f7
Коммит b572705486
2 изменённых файлов: 15 добавлений и 36 удалений

Просмотреть файл

@ -9377,16 +9377,6 @@ Init_date_core(void)
de_define_method(cDate, "nth_kday?", d_lite_nth_kday_p, 2);
#endif
rb_define_private_method(cDate, "hour", d_lite_hour, 0);
rb_define_private_method(cDate, "min", d_lite_min, 0);
rb_define_private_method(cDate, "minute", d_lite_min, 0);
rb_define_private_method(cDate, "sec", d_lite_sec, 0);
rb_define_private_method(cDate, "second", d_lite_sec, 0);
rb_define_private_method(cDate, "sec_fraction", d_lite_sec_fraction, 0);
rb_define_private_method(cDate, "second_fraction", d_lite_sec_fraction, 0);
rb_define_private_method(cDate, "offset", d_lite_offset, 0);
rb_define_private_method(cDate, "zone", d_lite_zone, 0);
rb_define_method(cDate, "julian?", d_lite_julian_p, 0);
rb_define_method(cDate, "gregorian?", d_lite_gregorian_p, 0);
rb_define_method(cDate, "leap?", d_lite_leap_p, 0);
@ -9398,8 +9388,6 @@ Init_date_core(void)
rb_define_method(cDate, "julian", d_lite_julian, 0);
rb_define_method(cDate, "gregorian", d_lite_gregorian, 0);
rb_define_private_method(cDate, "new_offset", d_lite_new_offset, -1);
rb_define_method(cDate, "+", d_lite_plus, 1);
rb_define_method(cDate, "-", d_lite_minus, 1);
@ -9631,19 +9619,16 @@ Init_date_core(void)
rb_define_singleton_method(cDateTime, "jisx0301",
datetime_s_jisx0301, -1);
#define f_public(m,s) rb_funcall(m, rb_intern("public"), 1,\
ID2SYM(rb_intern(s)))
f_public(cDateTime, "hour");
f_public(cDateTime, "min");
f_public(cDateTime, "minute");
f_public(cDateTime, "sec");
f_public(cDateTime, "second");
f_public(cDateTime, "sec_fraction");
f_public(cDateTime, "second_fraction");
f_public(cDateTime, "offset");
f_public(cDateTime, "zone");
f_public(cDateTime, "new_offset");
rb_define_method(cDateTime, "hour", d_lite_hour, 0);
rb_define_method(cDateTime, "min", d_lite_min, 0);
rb_define_method(cDateTime, "minute", d_lite_min, 0);
rb_define_method(cDateTime, "sec", d_lite_sec, 0);
rb_define_method(cDateTime, "second", d_lite_sec, 0);
rb_define_method(cDateTime, "sec_fraction", d_lite_sec_fraction, 0);
rb_define_method(cDateTime, "second_fraction", d_lite_sec_fraction, 0);
rb_define_method(cDateTime, "offset", d_lite_offset, 0);
rb_define_method(cDateTime, "zone", d_lite_zone, 0);
rb_define_method(cDateTime, "new_offset", d_lite_new_offset, -1);
rb_define_method(cDateTime, "to_s", dt_lite_to_s, 0);

Просмотреть файл

@ -187,18 +187,18 @@ class TestSH < Test::Unit::TestCase
d = Date.jd(Rational(2451944))
assert_equal(2451944, d.jd)
d = Date.jd(2451944.5)
assert_equal([2451944, 12], [d.jd, d.send('hour')])
assert_equal(2451944, d.jd)
d = Date.jd(Rational('2451944.5'))
assert_equal([2451944, 12], [d.jd, d.send('hour')])
assert_equal(2451944, d.jd)
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')])
assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
d = Date.civil(2001, 2, Rational('3.5'))
assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')])
assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
d = Date.ordinal(2001, 2.0)
assert_equal([2001, 2], [d.year, d.yday])
@ -266,10 +266,8 @@ class TestSH < Test::Unit::TestCase
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)
assert_equal(Encoding::US_ASCII, d.zone.encoding)
end
def test_to_s
@ -534,7 +532,6 @@ class TestSH < Test::Unit::TestCase
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
@ -542,7 +539,6 @@ class TestSH < Test::Unit::TestCase
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
@ -550,7 +546,6 @@ class TestSH < Test::Unit::TestCase
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"
@ -564,7 +559,6 @@ class TestSH < Test::Unit::TestCase
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"