Created
September 17, 2009 04:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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