LewlSauce
LewlSauce

Reputation: 5872

Ruby on Rails - Make ALL time (Time, DateTime), etc, as Central

So I'm using Delayed::Job for part of my Rails project and what's extremely frustrating and confusing is that the job isn't running at the specified time. I have a feeling because it's scheduling the jobs to run at UTC time instead of CST.

In my config/application.rb file I have the following two lines:

config.time_zone = "Central Time (US & Canada)"
config.active_record.default_timezone = :local

However, when I look at the list of delayed jobs and their updated_at, created_at and run_at times, they're completely different time zones. They're UTC, about 6 hours off.

Is there any way that I can just make everything CST, globally? This is annoying and very confusing because now I have to try to figure out how to convert times, hope things match up, etc.

Upvotes: 1

Views: 46

Answers (2)

iceveda06
iceveda06

Reputation: 619

Can you try the following?

Time.now.in_time_zone("Central Time (US & Canada)")

You can find the names of the ActiveSupport time zones by doing:

ActiveSupport::TimeZone.all.map(&:name)

or for just US

ActiveSupport::TimeZone.us_zones.map(&:name)

Upvotes: 1

Daniel
Daniel

Reputation: 101

Perhaps you should consider storing the time in UTC and manipulate it from UTC (normally this is a lot easier and why it is convention). If a user needs to view the time, then show central time from a view.

Upvotes: 0

Related Questions