Created
January 7, 2012 02:22
-
-
Save mgreenly/1573519 to your computer and use it in GitHub Desktop.
Extending Date._parse in Ruby
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
| # 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