Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Created January 7, 2012 02:22
Show Gist options
  • Select an option

  • Save mgreenly/1573519 to your computer and use it in GitHub Desktop.

Select an option

Save mgreenly/1573519 to your computer and use it in GitHub Desktop.
Extending Date._parse in Ruby
# lib/core_ext/date.rb
require 'date'
class Date
class << self
alias :original_parse :_parse
def _parse(input, comp=true)
# mm-dd-yyyy
if input =~ /^(\d{1,2})[^\d\w\s](\d{1,2})[^\d\w\s](\d{4})([T|\W].*)?/
modified_input = "%0.4d/%0.2d/%0.2d#{$4}" % [$3, $1, $2]
else
modified_input = input
end
original_parse modified_input, comp
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment