-
-
Save ingeniarius/1205977 to your computer and use it in GitHub Desktop.
Use american date format as default in Ruby 1.9
This file contains 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
# Date.parse() with Ruby 1.9 is now defaulting to the European date style where the format is DD/MM/YYYY, not MM/DD/YYYY | |
# patch it to use US format by default | |
if RUBY_VERSION >= '1.9' | |
class String | |
def to_date | |
if self.blank? | |
nil | |
elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/ | |
::Date.civil($3.to_i, $1.to_i, $2.to_i) | |
else | |
::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday)) | |
end | |
end | |
end | |
class ActiveRecord::ConnectionAdapters::Column | |
def self.fallback_string_to_date(string) | |
string.to_date | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment