Container timezone with meteor-up

I have recently run into an interesting mismatch between development environment and production environment. I am using meteor-up with zodern/meteor:latest to deploy to a local server. Even though both the development and production environment are running linux with timezone CET +0100, they do not agree on the timezone to use for dates in the MongoDB shell and the node process: the production environment shows UTC times in both (for instance using Date() in npx mup mongo shell) while the development environment uses the correct timezone. Note that on the server, it is only the production environment that causes problem (some docker containers fired by meteor-up), trying Date() in node or meteor node does yield the correct zoned dates. This leads to issues in some date computations using date-fns.

I’d like to have both environments to behave the same. Any idea what’s the correct way to approach this problem? @zodern

PS: To workaround the specific symptoms I am witnessing, I think I will leverage date-fns-tz.
PPS: I ended up implementing my own hack on top of Intl.DateTimeFormat instead.

Since most servers default to UTC, I generally try to keep everything in UTC, even during local development so that time zone differences arise during development.

When I’m able to use Linux or Mac I do this with the environment variable set TZ=UTC. If I’m forced to use Windows the only way is to change your computer’s timezone, and for that I put this in my startup code:

// use this code to set computer's timezone to UTC when testing timezone stuff on Windows
// On windows this sets the computer's clock to UTC which is the only way.  Then when the process ends it set's it back
// but if the process is killed then it can be reset manually with: tzutil /s "New Zealand Standard Time"
console.log('setting timezone to UTC...');
const setTZ = require('set-tz')
setTZ('UTC');
1 Like

Thanks @wildhart! I ended up having to use TZ=... in the CI environment since that one do not share the same timezone as my development environment. For the production environment, I guess the same TZ variable could be set in the env section of the meteor-up app configuration.