Search code examples
ruby-on-railsdelayed-job

Why is delayed_job recording an incorrect time stamp in the delayed_jobs table?


I feel I'm having a similar issue to this post Why is the timezone off in delayed_job?

I've setup my time_zone in config/application.rb as follows:

module Bane
  class Application < Rails::Application
    config.time_zone 'Eastern Time (US & Canada)'
  end
end

When looking at my delayed_jobs.log I record the time stamp shows correctly. However, when I look at my delayed_jobs table it shows 2015-11-19 14:25:11.637 which isn't what I had expected (2015-11-19 09:25:11.xxx).


Solution

  • When you set the config.time_zone setting Rails still stores the dates using UTC, but converts them to the desired time zone once the record is loaded.

    There is an another setting — config.active_record.default_timezone, which affects the way dates are stored in the db, but as far as I know it can only be set to either :local, either (the default) :utc. But if you can set your server time zone to EST then, I believe, it should work.

    EDIT: It seems that you can actually set any timezone for the default_timezone also. For example: config.active_record.default_timezone = 'Eastern Time (US & Canada)'.