Quando
Quando is a configurable date parser. Show it what's what and parse any (Gregorian calendar) date. Quando can be configured on:
Application-level:
Quando.configure do |c|
c.dlm = /[ ,-]/
c.jan = /janeiro/i
c.feb = /fevereiro/i
c.mar = /março/i
c.apr = /abril/i
# …
c.unimonth!
c.formats = [
/#{c.day} #{c.dlm} #{c.month_txt} #{c.dlm} #{c.year}/xi,
/#{c.year} #{c.dlm} #{c.month_txt} #{c.dlm} #{c.day}/xi,
]
end
Quando.parse('14-abril-1965') #=> #<Date: 1965-04-14>
Quando.parse('1965, abril 14') #=> #<Date: 1965-04-14>
Instance-level:
It will not affect your application-level configuration.
Quando.parse('14-abril-1965') #=> nil
date_parser = Quando::Parser.new.configure do |c|
# here be the options from the previous example
end
date_parser.parse('14-abril-1965') #=> #<Date: 1965-04-14>
Quando.parse('14-abril-1965') #=> nil
Or just one-time usage:
m = /(?<year>#{Quando.config.year}) (?<day>\d\d) (?<month>[A-Z]+)/i
Quando.parse('1965 14 Apr', matcher: m) #=> #<Date: 1965-04-14>
Enjoy.