class Pipio::TimeParser

Constants

NO_DATE
UNPARSEABLE_BY_DATETIME_PARSE

01/22/2008 03:01:45 PM

Public Class Methods

new(year, month, day) click to toggle source
# File lib/pipio/time_parser.rb, line 8
def initialize(year, month, day)
  @fallback_date_string = "#{year}-#{month}-#{day}"
end

Public Instance Methods

parse(timestamp) click to toggle source
# File lib/pipio/time_parser.rb, line 12
def parse(timestamp)
  if timestamp
    if has_no_date?(timestamp)
      parse_with_date(@fallback_date_string + " " + timestamp)
    else
      parse_with_date(timestamp)
    end
  end
end

Private Instance Methods

has_no_date?(timestamp) click to toggle source
# File lib/pipio/time_parser.rb, line 32
def has_no_date?(timestamp)
  timestamp.strip =~ NO_DATE
end
parse_with_date(timestamp) click to toggle source
# File lib/pipio/time_parser.rb, line 24
def parse_with_date(timestamp)
  begin
    Time.parse(timestamp)
  rescue ArgumentError
    Time.strptime(timestamp, UNPARSEABLE_BY_DATETIME_PARSE)
  end
end