I am having a hard time migrating from my local (MySQL-Rails3) stack to Heroku's (PostgreSQL) stack. The code works fine on local machine but gives unwanted results on Heroku.
On my local machine:
tickets = Ticket.where(:created_at => (Time.now.midnight.utc)..(Time.now.end_of_day.utc))
For instance, if the time now is July 9 2011 10:10am (local time), the above code would return all tickets created today (between July 9 2011 05:00 UTC and July 10 2011 05:00 UTC).
But on Heroku, the same 开发者_运维问答code is returning tickets created on July 9 2011 UTC regardless of the time. So tickets created July 9 2011 00:10 UTC would be included (that would be yesterday's tickets).
My understanding is that the code should work for PostgreSQL (obvisously it doesn't). How do I fix it so that the search criteria includes the time on PostgreSQL?
Could you be having a timezone problem? I'd guess that Heroku instances run in UTC by default because that's really the only sensible default. You could try to change your Heroku timezone:
$ heroku config:add TZ=where_ever/you_are
Also have a look at your config.time_zone
setting.
You should also switch your development environment to PostgreSQL to match your deployment environment.
精彩评论