Last active
December 15, 2015 08:49
-
-
Save strathmeyer/5234243 to your computer and use it in GitHub Desktop.
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
require 'date' | |
def parse_whackness(date_string) | |
year = parse_year(date_string) | |
month, day = guess_day_month(date_string[0..-5]) | |
Date.new(year.to_i, month.to_i, day.to_i) | |
end | |
def guess_day_month(date_string) | |
case date_string.length | |
when 4 | |
return date_string[0..1], date_string[2..3] | |
when 3 | |
if (10..12).include?(date_string[0..1].to_i) && | |
(1..9).include?(date_string[2].to_i) | |
return date_string[0..1], date_string[2] | |
else | |
return date_string[0], date_string[1..2] | |
end | |
when 2 | |
return date_string[0], date_string[1] | |
end | |
end | |
def parse_year(date_string) | |
date_string[-4..-1] | |
end | |
parse_whackness('3242013') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment