diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 72d697c..88f8ef4 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -2621,9 +2621,9 @@ offset_to_sec(VALUE vof, int *rof) if (!FIXNUM_P(vn)) return 0; n = FIX2LONG(vn); - if (n < -DAY_IN_SECONDS || n > DAY_IN_SECONDS) - return 0; } + if (n < -DAY_IN_SECONDS || n > DAY_IN_SECONDS) + return 0; *rof = (int)n; return 1; } diff --git a/test/date/test_date_new.rb b/test/date/test_date_new.rb index eddeeff..8973eef 100644 --- a/test/date/test_date_new.rb +++ b/test/date/test_date_new.rb @@ -192,6 +192,21 @@ def test_civil__ex end end + def test_civil__offset + d = DateTime.civil(2001,2,3, 0,0,0, Rational(1, 1)) + assert_equal(1.to_r, d.offset) + d = DateTime.civil(2001,2,3, 0,0,0, Rational(-1, 1)) + assert_equal(-1.to_r, d.offset) + + # An out-of-range offset is ignored, as it is for the equivalent Integer. + d = DateTime.civil(2001,2,3, 0,0,0, 2) + assert_equal(0, d.offset) + d = DateTime.civil(2001,2,3, 0,0,0, Rational(2, 1)) + assert_equal(0, d.offset) + d = DateTime.civil(2001,2,3, 0,0,0, Rational(49710, 1)) + assert_equal(0, d.offset) + end + def test_civil__reform d = Date.jd(Date::ENGLAND, Date::ENGLAND) dt = DateTime.jd(Date::ENGLAND, 0,0,0,0, Date::ENGLAND)