Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set time zone in code in a Firebase Cloud Function v2 scheduled function?

In Firebase Cloud Functions v1, configuring the time zone for scheduled functions could be done in the function’s signature.

exports.v1ScheduledFunction = functions.pubsub.schedule("every day 00:00")
                                              .timeZone("Etc/GMT+12")
                                              .onRun(async (context) => {
    ...
});

However, with the syntax changes in v2, this changes.

exports.v2ScheduledFunction = onSchedule("every day 00:00", async (event) => {
    ...
});

The documentation says that v2 can take Unix Crontab and App Engine syntax for the string schedule. However, I don’t think you can specify time zone in either Unix Crontab or App Engine syntax. Is there a way to specify time zone for scheduled functions in v2 in code? If not, how can it be done?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Per the API reference, the first parameter is either a schedule or a scheduler.ScheduleOptions object. FYI: This options object can also contain options in GlobalOptions (secrets, region, etc.).

To specify a time zone, you would use:

exports.v2ScheduledFunction = onSchedule(
  {
    schedule: "every day 00:00",
    timeZone: "Etc/GMT+12"
  },
  async (event) => {
    // your function code
  }
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading