I have a date which works fine when using it as English
> Date.strptime("Aug 02, 2015", "%b %d, %Y")
Sun, 02 Aug 2015
However when I use it another language es
, that doesnt work. E.g.
> Date.strptime("ago 02, 2015", "%b %d, %Y")
ArgumentError: invalid date
The text strings ago 02, 2015
itself comes from another service, and I need to standardize it to a particular format such as
> I18n.localize(Date.strptime("Aug 02, 2015", "%b %d, %Y"), format: "%m/%d/%Y")
"08/02/2015"
Is there a way to do this in Ruby, so that
> I18n.localize(Date.strptime("ago 02, 2015", "%b %d, %Y"), format: "%m/%d/%Y")
"08/02/2015"
I'm assuming you've already tried the following function which handles most scenarios for turning something into a DateTime object.
Other than that you can try appending to the date constants so that it properly picks them up. Personally haven't tried this approach but might work for you?
Lastly, have you considered using the Chronic Gem for date parsing? I believe it should handle cross language cases.