When a user clicks on a day in my calendar, I pass a JavaScript time variable to my Rails controller using Ajax.
Everything works perfectly when I test it locally, but once deployed on the server, the date appears to be one day behind the actual day clicked.
Upon initial page load with the calendar, the correct day is displayed and I utilize: day = Time.now.to_date.to_s(:db)
When a user selects a day on the calendar, the following JavaScript statement is executed:
start_date: Math.floor(new Date(date).getTime()/1000)
This translates to:
1362549600
and is then passed through Ajax into this Rails controller method:
start_date = Time.at(params[:start_date].to_i).to_date.to_s(:db)
logger.info "start_date = #{start_date}"
logger.info "time = #{Time.at(params[:start_date].to_i).to_datetime.to_s(:db)}"
The output from the logger is:
start_date = 2013-03-05
time = 2013-03-05 22:00:00
I have specified my timezone in config/application.rb as:
config.time_zone = 'Central Time (US & Canada)'
Do you have any suggestions on resolving this issue? Am I passing the date incorrectly from JavaScript to Rails?
EDIT
In my JavaScript code snippet, the initial value of date
is
Wed Feb 06 2013 00:00:00 GMT-0600 (CST)
Another point worth mentioning is that my server operates on PDT while I am located in the central time zone.
$ date
Tue Mar 19 16:51:52 PDT 2013
When running my application locally, the logger output shows:
start_date = 2013-03-06
time = 2013-03-06 00:00:00
This difference between yesterday and today leaves me unsure about what needs to be adjusted to correct this discrepancy.