I'm trying to parse some dates with bad formatting in Ruby. I decided to hinge part of the method on the presence of am or pm, so I've split the string there.
def bad_date(date)
if date.match(/m\d/i)
date_time = date.split('m', 2).reverse
time = date_time.include?('m')
date = date_time - time
else
date
end
end
It split in the right place and reverse the array it's all good, but it takes the m with it. How can I replace it? Or how can I avoid that entirely?
Essentially I'm trying to convert some dates like this:
dates
=> ["0900am06/13/2015", "0900 am06/13/2015", "0900am 06/13/2015", "0900 am 06/13/2015"]
Into this:
2015-06-13 09:00 AM
With an acceptable margin of error.
m. Hope it helps!