1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Use Regexp#match? in time.rb for conditionals

[Fix GH-1852]

From: Bart <bartdewater@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-28 10:22:57 +00:00
parent d02b7bd864
commit 1b91e1ce32

View file

@ -136,7 +136,7 @@ class Time
zone = zone.upcase zone = zone.upcase
if /\A([+-])(\d\d)(:?)(\d\d)(?:\3(\d\d))?\z/ =~ zone if /\A([+-])(\d\d)(:?)(\d\d)(?:\3(\d\d))?\z/ =~ zone
off = ($1 == '-' ? -1 : 1) * (($2.to_i * 60 + $4.to_i) * 60 + $5.to_i) off = ($1 == '-' ? -1 : 1) * (($2.to_i * 60 + $4.to_i) * 60 + $5.to_i)
elsif /\A[+-]\d\d\z/ =~ zone elsif zone.match?(/\A[+-]\d\d\z/)
off = zone.to_i * 3600 off = zone.to_i * 3600
elsif ZoneOffset.include?(zone) elsif ZoneOffset.include?(zone)
off = ZoneOffset[zone] * 3600 off = ZoneOffset[zone] * 3600
@ -168,11 +168,7 @@ class Time
# They are not appropriate for specific time zone such as # They are not appropriate for specific time zone such as
# Europe/London because time zone neutral, # Europe/London because time zone neutral,
# So -00:00 and -0000 are treated as UTC. # So -00:00 and -0000 are treated as UTC.
if /\A(?:-00:00|-0000|-00|UTC|Z|UT)\z/i =~ zone zone.match?(/\A(?:-00:00|-0000|-00|UTC|Z|UT)\z/i)
true
else
false
end
end end
private :zone_utc? private :zone_utc?
@ -521,14 +517,14 @@ class Time
# You must require 'time' to use this method. # You must require 'time' to use this method.
# #
def httpdate(date) def httpdate(date)
if /\A\s* if date.match?(/\A\s*
(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\x20 (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\x20
(\d{2})\x20 (\d{2})\x20
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20 (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
(\d{4})\x20 (\d{4})\x20
(\d{2}):(\d{2}):(\d{2})\x20 (\d{2}):(\d{2}):(\d{2})\x20
GMT GMT
\s*\z/ix =~ date \s*\z/ix)
self.rfc2822(date).utc self.rfc2822(date).utc
elsif /\A\s* elsif /\A\s*
(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\x20 (?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\x20