diff options
author | sonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-17 17:46:22 +0000 |
---|---|---|
committer | sonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-17 17:46:22 +0000 |
commit | b8f2f4dbcc6cf10a624543e2bd97e2565b1bb182 (patch) | |
tree | 08482a678d9ee82ca5296764028d450bf36e90b3 /lib | |
parent | 84ecf8e4e6d31778b157f0fffa3fb0973ffb56af (diff) | |
download | ruby-b8f2f4dbcc6cf10a624543e2bd97e2565b1bb182.tar.gz |
* lib/time.rb (parse, strptime): Fix Time.parse/strptime does not
have compatibility with DateTime.parse/strptime in terms of parsing
timezone [Bug #12190] [Fix GH-1297]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/time.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/time.rb b/lib/time.rb index 69e524fd61..61e973a461 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -249,14 +249,18 @@ class Time end private :apply_offset - def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, now) + def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, offset, now) if !year && !mon && !day && !hour && !min && !sec && !sec_fraction raise ArgumentError, "no time information in #{date.inspect}" end - off_year = year || now.year off = nil - off = zone_offset(zone, off_year) if zone + if offset + off = offset + else + off_year = year || now.year + off = zone_offset(zone, off_year) if zone + end if off now = now.getlocal(off) if now.utc_offset != off @@ -287,8 +291,10 @@ class Time sec ||= 0 usec ||= 0 - if year != off_year - off = nil + off = nil + if offset + off = offset + elsif year != off_year off = zone_offset(zone, year) if zone end @@ -363,7 +369,7 @@ class Time d = Date._parse(date, comp) year = d[:year] year = yield(year) if year && !comp - make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now) + make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], d[:offset], now) end # @@ -441,7 +447,7 @@ class Time else year = d[:year] year = yield(year) if year && block_given? - t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now) + t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], d[:offset], now) end t end |