sciman
sciman

Reputation: 43

Cannot set Heroku timezone

I need to have my app display times in a local timezone. Locally I'm using Time.zone = "Athens" in application.rb and it works fine.

For Heroku I used "heroku config:add TZ=Europe/Athens". This works fine for every operation I do from the command line, but it doesn't apply to my app.

For example

heroku run date: Running date attached to terminal... up, run.4786 Tue Apr 23 15:13:51 EEST 2013

heroku run console:

Order.last.created_at => Tue, 23 Apr 2013 13:15:53 EEST +03:00

Time.zone => (GMT+02:00) Athens

But I put this in my rails view: <%= Time.zone %> And I get this: (GMT+00:00) UTC And my times appear in UTC time in the actual app.

So, how do I set the timezone to apply to the actual rails application on heroku (and not just the console).

Upvotes: 4

Views: 4176

Answers (3)

praaveen V R
praaveen V R

Reputation: 1261

For setting up the timezone in heroku you can set it from terminal

$ heroku config:add TZ="Asia/Jerusalem"

Source https://coderwall.com/p/j9_e8a/set-timezone-for-your-heroku-app

Upvotes: 0

Daniel Romero
Daniel Romero

Reputation: 1588

Try to set the time zone in your application.rb as follows:

config.time_zone = 'Athens'
config.active_record.default_timezone = :local

config.active_record.default_timezone determines whether to use Time.local (if set to :local) or Time.utc (if set to :utc) when pulling dates and times from the database. The default is :utc for Rails, although Active Record defaults to :local when used outside of Rails.

from: http://guides.rubyonrails.org/configuring.html#configuring-active-record

Upvotes: 10

friism
friism

Reputation: 19279

Have you tried setting the time zone in application.rb as described here?

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

Upvotes: 0

Related Questions