Skip to content

Instantly share code, notes, and snippets.

@JuanitoFatas
Last active September 4, 2015 04:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanitoFatas/26ea90a89b324f83108c to your computer and use it in GitHub Desktop.
Save JuanitoFatas/26ea90a89b324f83108c to your computer and use it in GitHub Desktop.
Heroku Time Zone Rails 4

I have an date field. Used in two places. They are off by a day with each other when display.

 # 4/15
= local_time(user.create_date) # https://github.com/basecamp/local_time

# 4/16
= f.input :create_date, as: :string, input_html: { value: f.object.create_date && l(f.object.create_date, format: :long) }

It is because user.create_date is UTC, and local_time will display to suit where you are.

But setting the Time Zone can also do the job. So I set in config/application.rb:

config.time_zone = "Taipei"

But they are still off by a day, after a bit googled, I found everyone says need to add TZ ENV variable:

$ heroku config:add TZ=Taipei

And it worked, but I do not find any docs about this on Heroku Dev Center.

This probably a bad practice. Should always stored UTC in database. But works for now.

Thanks for reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment