summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/time.rb12
-rw-r--r--test/test_time.rb1
3 files changed, 13 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 744db59f84..af14c8a5be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat May 3 20:21:38 2014 Tanaka Akira <akr@fsij.org>
+
+ * lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not
+ given.
+ Reported by tadayoshi funaba. [ruby-core:62322]
+
Sat May 3 04:04:16 2014 Eric Wong <e@80x24.org>
* complex.c (parse_comp): replace ALLOCA_N with ALLOCV_N/ALLOCV_END
diff --git a/lib/time.rb b/lib/time.rb
index e346a3e587..8ffd42dcd7 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -393,16 +393,16 @@ class Time
d = Date._strptime(date, format)
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
if seconds = d[:seconds]
- if offset = d[:offset]
- Time.at(seconds).localtime(offset)
- else
- Time.at(seconds)
- end
+ t = Time.at(seconds)
else
year = d[:year]
year = yield(year) if year && block_given?
- make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+ t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+ end
+ if offset = d[:offset]
+ t.localtime(offset)
end
+ t
end
MonthValue = { # :nodoc:
diff --git a/test/test_time.rb b/test/test_time.rb
index 582e60b8ae..0496af855e 100644
--- a/test/test_time.rb
+++ b/test/test_time.rb
@@ -402,6 +402,7 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
assert_equal(false, Time.strptime('0', '%s').utc?)
assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
+ assert_equal(-7200, Time.strptime('20010203 -0200', '%Y%m%d %z').utc_offset)
end
def test_nsec