Setting DB Timezone in Padrino

All timestamps in Amethyst’s database are in UTC.  Out of the box, Padrino and ActiveRecord assume they are in the local timezone. There may be a better way (i.e., ORM agnostic), but this works for ActiveRecord.  In config/boot.rb:

##
# Add your before load hooks here
#
Padrino.before_load do
I18n.locale = :en
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
end

The first assignment sets the default locale (found this in the Padrino Localization guide).  The next two are ActiveRecord specific.  I dug into the Rails lib/initializer.rb code to find them.

Leave a Reply

You must be logged in to post a comment.