diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-03 11:31:33 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-03 11:31:33 +0000 |
commit | 4de238663a6e6d6b4f5306bb5f88a9e067c4f4c0 (patch) | |
tree | 42e904483f055e1ce400b26d8a26fe2111183274 | |
parent | 38656e24bea4a6ced1ebc18a0178bf8c1b175ca7 (diff) |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/time.rb | 12 | ||||
-rw-r--r-- | test/test_time.rb | 1 |
3 files changed, 13 insertions, 6 deletions
@@ -1,3 +1,9 @@ +Sat May 3 20:21:38 2014 Tanaka Akira <[email protected]> + + * 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 <[email protected]> * 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 |