diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 37d00d1..b3b9944 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -3638,12 +3638,17 @@ date_s_today(int argc, VALUE *argv, VALUE klass) static VALUE rt_rewrite_frags(VALUE hash) { - VALUE seconds; + VALUE seconds, offset; seconds = ref_hash("seconds"); if (!NIL_P(seconds)) { VALUE d, h, min, s, fr; + offset = ref_hash("offset"); + if(!NIL_P(offset)) { + seconds = f_add(seconds, offset); + } + d = f_idiv(seconds, INT2FIX(DAY_IN_SECONDS)); fr = f_mod(seconds, INT2FIX(DAY_IN_SECONDS)); @@ -3662,7 +3667,6 @@ rt_rewrite_frags(VALUE hash) set_hash("sec", s); set_hash("sec_fraction", fr); del_hash("seconds"); - del_hash("offset"); } return hash; } diff --git a/test/date/test_date_strptime.rb b/test/date/test_date_strptime.rb index f8483f9..e37be57 100644 --- a/test/date/test_date_strptime.rb +++ b/test/date/test_date_strptime.rb @@ -308,6 +308,12 @@ class TestDateStrptime < Test::Unit::TestCase DateTime.strptime('2002-03-14T11:22:33.123456789-09:00', '%FT%T.%N%Z')) end + def test_strptime_bug_7445 + d = DateTime.strptime('0 +0100', '%s %z') + assert_equal Rational(1, 24), d.offset + assert_equal 0, d.second + end + def test_strptime__2 n = 10**9 (Date.new(2006,6,1)..Date.new(2007,6,1)).each do |d|