class InternationalDateParser::Date

Constants

MONTH_TO_PARSE
MONTH_TRANSLATIONS
MONTH_TRANSLATIONS_SHORT

Public Class Methods

date_to_english(date) click to toggle source
# File lib/international_date_parser.rb, line 47
def self.date_to_english(date)
  month_from = date[/[^\s\d,]{3,}/i].downcase      # Search for a month name
  month_index = MONTH_TRANSLATIONS.index(month_from) || MONTH_TRANSLATIONS_SHORT.index(month_from)
  date.scan(/\s[^\s\d,]{1,2}\s/).each{|s| date.sub!(s[/[^\s]+/],'') if s}
  date.downcase!
  date.sub!(month_from, Date::MONTHNAMES[month_index % 12 + 1]) if month_index
  date
end
parse_international(date) click to toggle source
# File lib/international_date_parser.rb, line 34
def self.parse_international(date)
  return nil if date.nil? || date.empty?
  if date.is_a? Array
    date.push(Date.today.year) if date.flatten.count <= 2
    date = date.join(" ")
  end
  if date.scan(/[a-zA-Z]/).empty?
    Date.parse(date)
  else
    Date.parse(date_to_english(date))
  end
end