Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 208
kidcoder SAVE UKRAINE Avatar asked Jul 17 '26 04:07

kidcoder SAVE UKRAINE


1 Answers

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
  }
)
like image 64
samthecodingman Avatar answered Jul 19 '26 22:07

samthecodingman