We're seeing some funky stuff when trying to do scopes in Rails 3 in regards to timezones. Let's say we have an attribute called start_at of type date time. In application.rb we have config.time_zone = 'Eastern Time (US & Canada)'
set based on our server location.
When someone sets start_at to something like '2014-02-22 at 7pm EST' in the db it's stored as '2014-02-23 01:00:00-5' so when I setup a named scope such as:
scope :tomorrow, where("start_at = ?", Date.tomorrow)
that record is wrongly returned. If I try something like this:
scope :tomorrow, where("start_at at time zone 'EST' = ?", Date.tomorrow)
it still doesn't work. How can I create scopes with db date time comparisons that account for the local timezone without having to do something ridiculous, such as:
scope :tomorrow, where("date(start_at - INTERVAL '5 hours') = ?", Date.tomorrow)