Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created September 17, 2009 04:50
Show Gist options
  • Save seven1m/188354 to your computer and use it in GitHub Desktop.
Save seven1m/188354 to your computer and use it in GitHub Desktop.
swap american date order so Ruby 1.9 Date._parse will understand it
# complete hack to swap date MM/DD/YYYY around to YYYY/MM/DD
# so Ruby 1.9 will parse American dates the way we like 'em
# (works in Rails due to use of alias_method_chain)
class Date
class << self
def _parse_with_american_date(str, comp=true)
_parse_without_american_date(str.sub(/(\d{1,2})\/(\d{1,2})\/(\d{4})/, '\3/\1/\2'), comp)
end
alias_method_chain :_parse, :american_date
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment