Skip to content
accelerando

Turn off RoRs automatic timezone conversion for columns

I couldn’t find this in the documents, but Geoff Buesing showed me the hooks to turn off Ruby On Rails’ automatic timezone conversions for some columns of a model or a complete model:

# Turn it off for just some columns
class Picture < ActiveRecord::Base
 def self.skip_time_zone_conversion_for_attributes
   [:created_at, :published_at]
 end
end
 
# Turin it off for the whole model
class Picture < ActiveRecord::Base
 def self.time_zone_aware_attributes
   false
 end
end

Thanks a lot!

2 Comments

  1. ashik ali wrote:

    Hi ,
    Actually I am developing rails front end application to integrate back end application via database . Not standalone Rails applications development.

    Highly appreciation for the rails developer to get the timezone as default also very easy to configure timezone .

    But when we talk about integrated application as like me that is java and rails both application access the same database where the situation
    I don’t like time conversion according to different timezones .

    So really it is very useful for me to integrate rails with java..etc without timezone conflict .

    Posted on 08-Apr-10 at 9:38 am | Permalink
  2. matt wrote:

    I was looking for the answer to that question all day. It works great. Thanks a lot !

    Posted on 18-Sep-10 at 9:05 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

*

Close
E-mail It