Last Updated: March 06, 2021
· coutermarsh

Schedule rails jobs in your users timezone

Struggled with this for a while today. Thought I'd share it!

Was trying to schedule sidekiq jobs to run at a specific time... based on our users timezone. Here's what I ended up going with.

This schedules a sidekiq job for 9:25am in the users timezone. = user.time_zone

user_time_to_utc ='2012-10-22 09:25:00').utc
puts "Scheduling for #{user.login} at #{user_time_to_utc}"


Also on gist:

1 Response
Add your response

I believe you'd want to set back to whatever it was before in the example above, otherwsie the Time class will be set to the last users zone until restart (or something else changes it).

An alternate might be:'2012-10-22 09:25:00')

over 1 year ago ·