Firebase-tools: Allow emulators to select TimeZone

Created on 20 May 2020  ·  8Comments  ·  Source: firebase/firebase-tools

When I emulate my cloud functions it uses my local time zone. It would be great to run emulators by setting the TimeZone I'd like to, in order to test the system as it can be in production (I'm most interested in testing cloud functions with UTC locale set, as I think that actually firebase uses UTC in the containers and not the region locale, right ? ).

Something like:
firebase emulators:start --tz='UTC'
firebase emulators:start --tz='Europe/Amsterdam'
or other format.

I tried to use (in node.js)
process.env.TZ = 'UTC'
and it worked, so I was wondering if could be possible to have an environment variable like that one that can be changed by param.

emulator-suite functions feature request

All 8 comments

@emanuelevivoli thanks for reporting this. In my opinion it would be better to infer this from the function region rather than allowing the user to set it, since we want to help people get production-like behavior.

Do you agree with that?

Hi @samtstern 👋, actually I think the best would be to set just UTC because, if I'm not mistaken, the cloud functions have timeZone set to UTC.
(Actually, that is what I think... but I'm not really sure about it, it's just that my functions seems to work like that.)

On the other hand, if cloud functions run in their region timezone, your option would be better (each one runs in it's own timezone).

Ps. If you know something more about UTC-notUTC please let me know 😅

@emanuelevivoli ok I think we're on the same page. Once I find out what production behavior is I will make sure the emulators automatically match that.

I don't know if it'll help, but I based my beliefs also to this thread on stackoverflow.

I did a simple check:

const functions = require('firebase-functions');

exports.checkTimeZone = functions.region(
  "us-central1",
  "asia-east2",
  "asia-northeast1",
  "europe-west1"
).https.onRequest((req, res) => {
  const now = new Date();
  const check = {
    tz: process.env.TZ,
    time: now.toTimeString(),
    offset: now.getTimezoneOffset()
  }
  console.log(JSON.stringify(check));
  res.json(check);
});
$ http -b https://us-central1-ota-fir-dumpster.cloudfunctions.net/checkTimeZone
{
    "offset": 0,
    "time": "15:55:04 GMT+0000 (UTC)"
}

samstern@samstern-macbookpro3 tmp.G5fBpLiE 
$ http -b https://asia-east2-ota-fir-dumpster.cloudfunctions.net/checkTimeZone
{
    "offset": 0,
    "time": "15:55:12 GMT+0000 (UTC)"
}

samstern@samstern-macbookpro3 tmp.G5fBpLiE 
$ http -b https://asia-northeast1-ota-fir-dumpster.cloudfunctions.net/checkTimeZone
{
    "offset": 0,
    "time": "15:55:21 GMT+0000 (UTC)"
}

samstern@samstern-macbookpro3 tmp.G5fBpLiE 
$ http -b https://europe-west1-ota-fir-dumpster.cloudfunctions.net/checkTimeZone
{
    "offset": 0,
    "time": "15:55:32 GMT+0000 (UTC)"
}

So it looks like they're all in the same time zone.

When I run the function locally from New Jersey I get this:

$ firebase functions:shell
i  functions: Loaded functions: checkTimeZone
⚠  functions: The following emulators are not running, calls to these services will affect production: firestore, database, pubsub
firebase > checkTimeZone()
Sent request to function.
firebase > >  {"time":"11:56:43 GMT-0400 (Eastern Daylight Time)","offset":240}

RESPONSE RECEIVED FROM FUNCTION: 200, {
  "time": "11:56:43 GMT-0400 (Eastern Daylight Time)",
  "offset": 240
}

But if I set TZ=UTC it works better locally:

$ TZ=UTC firebase functions:shell
i  functions: Loaded functions: checkTimeZone
⚠  functions: The following emulators are not running, calls to these services will affect production: firestore, database, pubsub
firebase > checkTimeZone()
Sent request to function.
firebase > >  {"tz":"UTC","time":"15:56:16 GMT+0000 (Coordinated Universal Time)","offset":0}

RESPONSE RECEIVED FROM FUNCTION: 200, {
  "tz": "UTC",
  "time": "15:56:16 GMT+0000 (Coordinated Universal Time)",
  "offset": 0
}

Super! I just tried
$ TZ=UTC firebase emulators:start
and it does what I was looking for.

Thanks ✌️

Was this page helpful?
0 / 5 - 0 ratings