Steps:
On my localhost server I select the time Jan 18, 2013 10 am – 11 am in my browser located in the Pacific time zone. I then select the exact same time on my production server on heroku.
As you can see the outputs of what is saved to the database are different. I want production to behave as localhost and take into account the timezone when storing the time as UTC. What is causing this? The heroku server is in EST, but that does not account for this behavior.
Controller:
def create
puts params[:event][:starts_at]
@event = Event.create!(params[:event])
puts @event.starts_at
end
Output Localhost:
Fri Jan 18 2013 10:00:00 GMT-0800 (PST)
2013-01-18 18:00:00 UTC
Output Heroku (production):
Fri Jan 18 2013 10:00:00 GMT-0800 (PST)
2013-01-18 10:00:00 UTC
Schema:
t.datetime "starts_at"
Env:
Ruby on Rails 3.2.11
Ruby 1.9.3
Postgres
Background on how PostgreSQL deals with date/time
I think your issue is covered in this answer from another SO question:
Specifically this answer:
Use this query for time in
UTCformat:Use this query for time in local timezone:
Rails & ActiveRecords & date/time
This rails/rails github issue also discusses it:
There is a comment by pixeltrix which says the following:
To fix the time in
ActiveRecordsso that it is always dealt with asUTCyou can set the following variable: