From 4de238663a6e6d6b4f5306bb5f88a9e067c4f4c0 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 3 May 2014 11:31:33 +0000 Subject: [PATCH] * lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not given. Reported by tadayoshi funaba. [ruby-core:62322] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/time.rb | 12 ++++++------ test/test_time.rb | 1 + 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 + + * 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 * 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