Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Scheduler timezone?

Tags:

heroku

What's the Heroku timezone for Scheduler? It says "UTC" but I'm not sure if that's correct. My tasks are starting at the wrong time despite converting the timezone correctly.

Thoughts?

like image 763
netwire Avatar asked Jun 26 '14 11:06

netwire


People also ask

What timezone does heroku use?

Heroku uses the UTC timezone for its logs by default. You can change it, although the recommended approach is to convert to the client's local timezone when displaying the data, for example with a library like Luxon.

How do I change timezone in Heroku?

Open your app's dashboard and navigate to the 'settings' tab, then under 'config variables' click the 'reveal config vars' button. You will then be able to add TZ = America/Chicago (or whatever timezone you need).

What time zone is dyno bot?

Best practice would be to store/use time in UTC and instead convert the UTC time as appropriate at the view layer/client side for display only. Note: this will not affect logs, as these are always in UTC.


1 Answers

This question's a bit old, but yes, Heroku Scheduler definitely uses UTC even if you specify a timezone in your app. I tested it with this code:

task :send_test_email => :environment do
  if Date.today.strftime("%A").downcase == 'monday'
    UserMailer.send_test_email(Time.now.strftime("%Z")).deliver
  end
end

I'm in Pacific time zone. I set Heroku Scheduler to run this every 10 minutes, and this email was able to send on Sunday night PST, which is Monday in UTC time. Also, the string I passed to the mailer,Time.now.strftime("%Z"), is set as the subject of the email which indeed read, "UTC"

One potential source of confusion is Daylight Saving Time. For example, UTC is always 8 hours ahead of Pacific Standard Time (PST - used for winter months), and 7 hours ahead of Pacific Daylight Time (PDT - used for summer months). So if your tasks are off by an hour, it could be you measured from the wrong UTC zone.

like image 187
n_i_c_k Avatar answered Sep 22 '22 00:09

n_i_c_k