Vita Rara: A Life Uncommon


Skipping UTC Conversion of Date/DateTime in ActiveRecord

Categories: | |

I'm in the process of porting an application from Java/Groovy to Ruby on Rails. All of our times are stored in the database in local time. So, I needed ActiveRecord to store a time without converting it to UTC, which 2.2 does by default. (I'm not sure when UTC became the standard though, could have been before 2.2.)

After some Googling and asking on IRC it was suggested I try:

config.active_record.default_timezone = :local

This sets the ActiveRecord::Base.default_timezone class attribute. Unfortunately that didn't seem to have the desired effect. Dates were still stored in UTC but when retrieved via accessors they were converted to local time. Not what I wanted.

Syndicate content