ActiveRecord doesn't care about timezone?

I’m having some trouble getting activerecord to adhere to my timezone
settings when finding objects based on its created_at field. I
understand that datetime fields are stored in UTC but it doesn’t
convert the datetimes when it performs the lookup. I basically
followed Railscasts #106 and I’m using Authlogic for authentication.
Thanks for any help.

http://gist.github.com/180080

This looks like an instance of this bug:

https://rails.lighthouseapp.com/projects/8994/tickets/2946

The quick way to fix it in this case is to convert the incoming
datetime objects to UTC in timeline_created_products.

–Matt J.

Yeah, I tried that in my example that I posted but the results aren’t
then converted back to the users timezone. So if a Product is sitting
in the database with created_at = 2009-09-03 02:39:22 UTC (which is
2009-09-02 21:39:22 CDT), it won’t come back converted to CDT.

I don’t think this is going to work - you’re grouping by the date in
the DB, where they are all UTC. The dates that come back don’t have
times, so there isn’t any way to convert them. (eg, 2009-09-03
02:39:22 UTC -> 2009-09-02 CDT, but 2009-09-03 2009-09-03 12:39:22 UTC
-> 2009-09-03 CDT)

The only way around it would be to add the offset back in on the SQL
side before converting to a date; how you manage that will be based on
which DB you’re using. Note that you’ll still have a mess on your
hands, as the two months where DST changes won’t have a consistent
offset…

–Matt J.

Yeah that sounds pretty nasty. To get around all this, I simply
changed my timeline endpoints to start at 30 days ago and end at
strictly less than today.midnight. That way I don’t include today’s
numbers which could possibly be wrong because of timezone
differences. Thanks Matt.