Skip to content

Instantly share code, notes, and snippets.

@strathmeyer
Last active December 15, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strathmeyer/5234243 to your computer and use it in GitHub Desktop.
Save strathmeyer/5234243 to your computer and use it in GitHub Desktop.
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