mardi 12 février 2019

Date is supposed to be validating to true but it is not

Rails 3.2

An action in one of my helper methods is failing, and I don't understand why. The code is:

paid_at = Date.strptime(params[:manually_paid_at], "%m-%d-%Y") rescue nil

I captured the value of params[:manually_paid_at], prior to this line of code, as follows:

logger.info("Manually paid at: #{params[:manually_paid_at]}")

and it is:

02/02/2019

As far as I know, this is a valid date. When I check by running a test console session, as follows:

$ rails c test
Loading test environment (Rails 3.2.18)
[1] pry(main)> mydate = "02/02/2019"
=> "02/02/2019"
[2] pry(main)> Date.strptime(mydate, "%m-%d-%Y")
ArgumentError: invalid date
from (pry):2:in `strptime'

What am I doing wrong. This is a valid date.

Aucun commentaire:

Enregistrer un commentaire