M.Octavio
M.Octavio

Reputation: 1808

Chronic - how to set a default year when parsing a month

I got an input field where the user inputs a date, currently I'm using Chronic and the user likes it.

If the user enters last jan using Chronic and strftime I get January 2013 which is good, the issue comes when:

the user input is an upcoming month like January, the parsing I'm doing returns January 2014 and not January 2013 wich is what the user wants.

result_date = Chronic.parse(params[:date]).strftime('%B %Y')

Is there a way that I can set as default the current year? So when the user puts January it is parsed to January 2013 ?

Thanks!

Upvotes: 0

Views: 147

Answers (1)

M.Octavio
M.Octavio

Reputation: 1808

I was able to figure it out!

result_date = Chronic.parse(params[:date], :context => :past).strftime('%B %Y')

Now if the user input is a single month like Jan the outcome will be January 2013

I hope it helps someone else!

Upvotes: 0

Related Questions