Class: UsageMod::TimeArgumentPlugin

Inherits:
ArgumentParserPlugin show all
Defined in:
lib/Usage.rb

Instance Attribute Summary

Attributes inherited from ArgumentParserPlugin

#value

Instance Method Summary collapse

Methods inherited from ArgumentParserPlugin

#close

Constructor Details

#initialize(usage_ui, str) ⇒ TimeArgumentPlugin

Returns a new instance of TimeArgumentPlugin.



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'lib/Usage.rb', line 441

def initialize(usage_ui, str)
  if /(\d+)\/(\d+)\/(\d+)-(\d+):(\d+)/.match(str) then
    month = $1.to_i
    day = $2.to_i
    if $3.size < 3 then
      year = $3.to_i + 2000
    else
      year = $3.to_i
    end
    hour = $4.to_i
    minute = $5.to_i
    @value = Time.local(year, month, day, hour, minute)
  else
    raise InvalidTimeError.new(str)
  end
end