I discovered Heroku a few weeks ago. It’s a great platform to deploy your apps, specially because of their Free plan which I’ve been using as dev env to work with my team remotely.

Lately I started working on a new project. On this particular project I rely on dates for most of the main operations. The app has a front-end built with Angular 5, and a back-end built with Node.js

Everything was working perfectly on my local environment, but when I deployed to Heroku all the date operations started to behave kind of random (spoilers: it wasn’t random at all).

Well, here’s the thing. I’m from Argentina, and I had the front-end deployed on a local server, but the back-end was on Heroku and the default region for new heroku apps is “us”. So basically my front-end and back-end were on different time zones.

This is not the first time I deal with this kind of date issues (there aren’t many local cloud services in my region) so I found the source of the problem almost immediately, and I wanted to share it with you in case you encounter a similar issue.

Luckily Heroku let’s us change the timezone of our app simply by adding a new config var.

From the Heroku CLI

  1. Open the command shell
  2. Login to heroku
  3. Navigate to your app’s directory
  4. Setup your TZ
heroku config:add TZ="America/Argentina/Buenos_Aires"

From the Heroku dashboard (web)

  1. Login into the Heroku dashboard from a browser
  2. Navigate to the app
  3. Click over the Settings tab
  4. Press the “Reveal Config Vars” button
  5. Set the key to “TZ” and the value to your timezone (E.g.: America/Argentina/Buenos_Aires)
  6. Press the Add button

How do I know which is the correct TZ value

Follow this link to see the complete list of time zones

Check the new TZ value

Use the following command to check the value of the new config var from Heroku CLI:

heroku config:get TZ

For more info about Heroku

What is Heroku?

For more info about Heroku’s Config Vars

Configuration and Config vars

This post is also available on DEV.