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.