Skip to content

Instantly share code, notes, and snippets.

@penguincoder
Created June 9, 2009 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save penguincoder/126742 to your computer and use it in GitHub Desktop.
Save penguincoder/126742 to your computer and use it in GitHub Desktop.
#
# © 2009 Andrew Coleman
# Released under MIT license.
# http://www.opensource.org/licenses/mit-license.php
#
# total hack to allow american style date parsing.
# does not allow european-ish date parsing, sorry.
#
module AmericanDateMonkeyPatch
def to_date
if 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
if RUBY_VERSION >= '1.9'
String.send :include, AmericanDateMonkeyPatch
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment