aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-17 17:46:22 +0000
committersonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-17 17:46:22 +0000
commit1ba62fa93a200f92a8bd612a14f36a298ac4b3d1 (patch)
tree08482a678d9ee82ca5296764028d450bf36e90b3 /lib
parent2169bea82e57c3887285b06f36b0f79827de0986 (diff)
downloadruby-1ba62fa93a200f92a8bd612a14f36a298ac4b3d1.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.rb20
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