diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 7353dc8..0b0ebdf 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -3361,6 +3361,9 @@ old_to_new(VALUE ajd, VALUE of, VALUE sg, { VALUE jd, df, sf, of2, t; + if (RB_TYPE_P(ajd, T_FLOAT)) + ajd = f_to_r(ajd); + decode_day(f_add(ajd, half_days_in_day), &jd, &df, &sf); t = day_to_sec(of); diff --git a/test/date/test_date_marshal.rb b/test/date/test_date_marshal.rb index 9990e3d..ab07159 100644 --- a/test/date/test_date_marshal.rb +++ b/test/date/test_date_marshal.rb @@ -79,6 +79,22 @@ def test_marshal_load_old_format_offset assert_equal(0, d.offset) end + def test_marshal_load_old_format_float + d = DateTime.allocate + d.marshal_load([0.25, 0, Date::ITALY]) + d2 = DateTime.jd(0, 18) + assert_equal(d2, d) + assert_equal(d2.hash, d.hash) + assert_equal(d, Marshal.load(Marshal.dump(d))) + + d = Date.allocate + d.marshal_load([0.5, Date::ITALY]) + d2 = Date.allocate + d2.marshal_load([Rational(1, 2), Date::ITALY]) + assert_equal(d2, d) + assert_equal(d2.hash, d.hash) + end + def test_memsize require 'objspace' t = DateTime.new(2018, 11, 13)