Skip to content

Instantly share code, notes, and snippets.

@conanite conanite/date.rb
Created Jan 30, 2012

Embed
What would you like to do?
ActiveRecord, I18n, Date, and UX
class Date
class << self
alias :_ruby_parse :_parse
def _parse(str, comp=true)
if I18n.locale.to_sym == :en
_ruby_parse str, comp
else
map = month_map I18n.locale
str = str.gsub /[^\s\/\d-]+/ do |month|
map[month.normalize] || month
end
_ruby_parse str, comp
end
end
private
def month_map locale
@@month_map ||= { }
@@month_map[locale] ||= make_month_map(locale)
end
def make_month_map locale
abbrev_months_en = I18n.t "date.abbr_month_names", :locale => :en
abbrev_months_local = I18n.t "date.abbr_month_names", :locale => locale
full_months_local = I18n.t "date.month_names", :locale => locale
result = { }
abbrev_months_en.each_with_index do |mon, i|
if mon
result[abbrev_months_local[i].normalize] = mon
result[full_months_local[i].normalize] = mon
end
end
result
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.