0

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!

4

1 回答 1

0

我能够弄清楚!

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

现在,如果用户输入是像 Jan 这样的一个月,结果将是 2013 年 1 月

我希望它可以帮助别人!

于 2013-06-13T17:11:23.947 回答