The time parsing refactoring introduced an unpleasant namespace
conflict by defining Utils::Time. Eliminate it by renaming it to
ParseTime
module ::Irc
module Utils
module ::Irc
module Utils
FLOAT_RX = /((?:\d*\.)?\d+)/
ONE_TO_NINE = {
FLOAT_RX = /((?:\d*\.)?\d+)/
ONE_TO_NINE = {
UNITSPEC_RX = /(s(?:ec(?:ond)?s?)?|m(?:in(?:ute)?s?)?|h(?:(?:ou)?rs?)?|d(?:ays?)?|weeks?)/
# str must much UNITSPEC_RX
UNITSPEC_RX = /(s(?:ec(?:ond)?s?)?|m(?:in(?:ute)?s?)?|h(?:(?:ou)?rs?)?|d(?:ays?)?|weeks?)/
# str must much UNITSPEC_RX
- def Time.time_unit(str)
+ def ParseTime.time_unit(str)
case str[0,1].intern
when :s
1
case str[0,1].intern
when :s
1
end
# example: half an hour, two and a half weeks, 5 seconds, an hour and 5 minutes
end
# example: half an hour, two and a half weeks, 5 seconds, an hour and 5 minutes
- def Time.parse_period(str)
+ def ParseTime.parse_period(str)
clean = str.gsub(/\s+/, ' ').strip
sofar = 0
clean = str.gsub(/\s+/, ' ').strip
sofar = 0
if clean.sub!(/^(#{FRACTION_RX})\s+#{UNITSPEC_RX}/, '')
# fraction followed by unit
num = FRACTIONS[$1.intern]
if clean.sub!(/^(#{FRACTION_RX})\s+#{UNITSPEC_RX}/, '')
# fraction followed by unit
num = FRACTIONS[$1.intern]
- unit = Time.time_unit($2)
+ unit = ParseTime.time_unit($2)
elsif clean.sub!(/^#{FLOAT_RX}\s*(?:\s+and\s+(#{FRACTION_RX})\s+)?#{UNITSPEC_RX}/, '')
# float plus optional fraction followed by unit
num = $1.to_f
frac = $2
elsif clean.sub!(/^#{FLOAT_RX}\s*(?:\s+and\s+(#{FRACTION_RX})\s+)?#{UNITSPEC_RX}/, '')
# float plus optional fraction followed by unit
num = $1.to_f
frac = $2
- unit = Time.time_unit($3)
+ unit = ParseTime.time_unit($3)
clean.strip!
if frac.nil? and clean.sub!(/^and\s+(#{FRACTION_RX})/, '')
frac = $1
clean.strip!
if frac.nil? and clean.sub!(/^and\s+(#{FRACTION_RX})/, '')
frac = $1
- unit = Time.time_unit($6)
+ unit = ParseTime.time_unit($6)
clean.strip!
if frac.nil? and clean.sub!(/^and\s+(#{FRACTION_RX})/, '')
frac = $1
clean.strip!
if frac.nil? and clean.sub!(/^and\s+(#{FRACTION_RX})/, '')
frac = $1
hour = $1.to_i
min = $2.to_i
sec = $3.to_i
hour = $1.to_i
min = $2.to_i
sec = $3.to_i
- now = ::Time.now
- later = ::Time.mktime(now.year, now.month, now.day, hour, min, sec)
+ now = Time.now
+ later = Time.mktime(now.year, now.month, now.day, hour, min, sec)
# if the given hour is earlier than current hour, given timestr
# must have been meant to be in the future
# if the given hour is earlier than current hour, given timestr
# must have been meant to be in the future
if ampm == "pm"
hour += 12
end
if ampm == "pm"
hour += 12
end
- now = ::Time.now
- later = ::Time.mktime(now.year, now.month, now.day, hour, min, now.sec)
+ now = Time.now
+ later = Time.mktime(now.year, now.month, now.day, hour, min, now.sec)
+ ParseTime.parse_period(str)