Time Zone issues on Heroku
I’ve run into this problem before and want to document the simple way that I finally fixed it.
I have Van model with a column called ‘departure_time’ in a Rails app this is a DateTime object. When a user/admin edits a van, they have a series of dropdowns to select the datetime using the datetime_select helper in Rails. Everything seems to be fine until I push to heroku, and then whenever I create a new van, or edit one, time time that I choose gets changed by 6 hours. I spend hour trying to figure this out on another app, and finally came across this simple solution:
I was using the bootstrap3-datetimepicker gem, which formats the datetime differently than what needs to go in the database, so I had to do some logic to parse that string into an acceptable datetime object, and then create a DateTime object with Time.new or Time.local.
Well, all I need to do to fixe the error is use Time.zone.local instead of Time.local. It now works locally and on Heroku.