Skip to content

Timezone Inconsistency #4000

Closed
Closed

Description

@mnappo

I think this is the expected behavior but maybe the documentation could be improved? There is an inconsistency in timezone when running an onRequest function via emulator endpoint vs calling it at functions.timezoned(req,res). Since we cannot wrap an onRequest function using firebase-functions-testing this behavior is observed.

[REQUIRED] Environment info

firebase-tools: 10.0.1

Platform: WSL2

[REQUIRED] Test case

/functions/index.js

const functions = require("firebase-functions");
exports.timeZoned = functions.https.onRequest((req,res)=>{
    let now = new Date()
    let response = now.getTimezoneOffset()
    res.status(200).send(response.toString())

/functions/test/index.test.js

const chai = require('chai')
const chaiHttp = require('chai-http')
chai.use(chaiHttp)
const assert = chai.assert
const functions = require('../index.js')

describe('Timezone Test', function(){
        it('is UTC from firebase-functions-test', function(){
            let res = {
                send: (response)=>{
                    console.log('Functions TZ Offset', response ) // output is 360
                },
                status: function (code){
                    return this
                },
                setHeader: (key, value) => {
                },
                getHeader: (value) => {
                },
            }
            let req = {}
            
           functions.timeZoned(req,res)
        })
        it('is America/Chicago from API Endpoint', function(done){
            chai.request('http://127.0.0.1:5001/{project-ID}/')
            .post('{region}/timeZoned')
            .send({})
            .end((err, res)=>{
                console.log('API TZ offet', res.text) // output is 0
                done()
            })
        })
    })

[REQUIRED] Steps to reproduce

Run firebase emulators:exc mocha

[REQUIRED] Expected behavior

Expect for functions to run in UTC timezone similar to production

[REQUIRED] Actual behavior

functions.timeZoned runs in my local time and the call to the emulator endpoint runs in UTC as expected

Activity

  1. self-assigned this
    on Jan 10, 2022
  2. abeisgoat commented on Jan 10, 2022

    @abeisgoat
    Contributor

    Sorry this is WAI, there is a way you can specify the timezone for Node using this technique but we don't do anything special to handle time in the emulators!

  3. mnappo commented on Jan 11, 2022

    @mnappo
    Author

    Thanks. I suspected that would be the case. For anyone finding this later, I started using getUTCHours/setUTCHours to avoid unexpected issues with local timezones.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions