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?
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With