Railties config.time_zone

Hi,

I have stumbled upon a small issue regarding the use of Railties
(Engine) and setting the time_zone.

It seems when I set the time_zone in my engine like:

class Engine < Rails::Engine
config.time_zone = ‘Brussels’
end

The actual time zone in the application is set back to the default ‘UTC’
.

But if I delay setting the time zone until after initialization:

class Engine < Rails::Engine
config.after_initialize do
Rails::Application.config.time_zone = ‘Brussels’
end
end

The time zone is set correctly.

On first glans, it seems that Rails doesn’t take the engine setting into
account, and goes ahead using the default Rails ‘UTC’ setting.

I don’t know if this is seen as expected behavior, but for me it seems
more logically that when you specify the time_zone setting in your
Engine, your application takes it into account. Unless of course you
overwrite it in your projects application.rb file.

Could someone elaborate on this?

Thank you in advance

It even seems that my previous code wasn’t correct.

when I use the after_initialize, the time_zone does get set in the
Rails.application, but not in the Time.zone.

The correct way for this seems to be

    config.before_initialize do |app|
      app.config.time_zone = 'Brussels'
    end

But still it is unclear to me if this is the expected behavior.

Michael R. wrote in post #1011396:

Hi,

I have stumbled upon a small issue regarding the use of Railties
(Engine) and setting the time_zone.

It seems when I set the time_zone in my engine like:

class Engine < Rails::Engine
config.time_zone = ‘Brussels’
end

The actual time zone in the application is set back to the default ‘UTC’
.

But if I delay setting the time zone until after initialization:

class Engine < Rails::Engine
config.after_initialize do
Rails::Application.config.time_zone = ‘Brussels’
end
end

The time zone is set correctly.

On first glans, it seems that Rails doesn’t take the engine setting into
account, and goes ahead using the default Rails ‘UTC’ setting.

I don’t know if this is seen as expected behavior, but for me it seems
more logically that when you specify the time_zone setting in your
Engine, your application takes it into account. Unless of course you
overwrite it in your projects application.rb file.

Could someone elaborate on this?

Thank you in advance