Why Is the Timezone Off in Delayed_Job

Why is the timezone off in delayed_job?

The problem was in my config/application.rb as @rainkinz suggested, specifically the 2nd line:

config.time_zone = 'Central Time (US & Canada)'
config.active_record.default_timezone = 'Central Time (US & Canada)'

Apparently the default_timezone setting is deprecated after Rails 3.2.13, which I just upgraded from a few days ago.

When I changed it to only have the local time zone set:

config.time_zone = 'Central Time (US & Canada)'
#config.active_record.default_timezone = 'Central Time (US & Canada)'

This fixed the problem. All active record objects still seem to have the correct time when saved, as do delayed_jobs.

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

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)'.

Rails DelayedJob run_at Time Zone discrepancy

You can do something like
ActiveSupport::TimeZone.new('Chennai').parse("5 pm").utc

Or ideally you could store your time as "17:00:00 +0530", so it's clear you mean the time in IST. Then simply Time.parse("17:00:00 +0530").utc would work too.

Current timestamp in mySQL is delayed by 30 minutes

This is most likely occurring because of the system timezone offset.

run this query to get the timezone offset of the system that mysql is running on

select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00'));

compare it with the timezone you are in.

Alternately you can run the following to get the correct time (replace the timezone with yours), but this means you would have to do it for every session.

SET time_zone='-06:00';
SELECT CURRENT_TIMESTAMP;

Is the Javascript date object always one day off?

Notice that Eastern Daylight Time is -4 hours and that the hours on the date you're getting back are 20.

20h + 4h = 24h

which is midnight of 2011-09-24. The date was parsed in UTC (GMT) because you provided a date-only string without any time zone indicator. If you had given a date/time string w/o an indicator instead (new Date("2011-09-24T00:00:00")), it would have been parsed in your local timezone. (Historically there have been inconsistencies there, not least because the spec changed more than once, but modern browsers should be okay; or you can always include a timezone indicator.)

You're getting the right date, you just never specified the correct time zone.

If you need to access the date values, you can use getUTCDate() or any of the other getUTC*() functions:

var d,
days;
d = new Date('2011-09-24');
days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat'];
console.log(days[d.getUTCDay()]);


Related Topics



Leave a reply



Submit