Before:
DateTime.strptime('0 +0100', '%s %z').strftime('%s %z')
=> "0 +0000"
After:
DateTime.strptime('0 +0100', '%s %z').strftime('%s %z')
=> "0 +0100"
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
···
From: Charlie Somerville <charliesome@ruby-lang.org>
---
ext/date/date_core.c | 8 ++++++--
test/date/test_date_strptime.rb | 6 ++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 5455630..5c84017 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -3686,12 +3686,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));
@@ -3710,7 +3715,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|
--
1.8.4-fc