Scheduled functions with Daylight Savings Time

I’m using a scheduled function that runs monday to friday at 10 am in my timezone:

import { schedule } from "@netlify/functions";

schedule('0 8 * * 1-5', handler);

Last weekend, the clock went back by 1 hour, for daylight savings time. Causing this script to run at 9 am today.

Is there a way to account for this in the scheduler-syntax? I’ve found some references (not in netlify) for crontab-commands to run in specific defined timezones, but that does not seem to apply here.

I doubt we have done anything specific around this, but I have asked our team if it’s a feature request or if there is some existing syntax to help out in the future. I expect it won’t matter until 6 months hence :slight_smile:

I’ve also suggested that we add this to the docs (what timezone our functions run in, which presumably is UTC which never changes, but instead, your timezone changed relative to UTC so you saw the function run at the “normal” time for us, but an hour off from your expectation).

1 Like

Thanks for following up!
I do get it is an edge case and there are some ways around it that I can code myself (like firing the function twice and checking the time in my timezone in javascript).
But for now I’m just going to change the schedule twice a year, but I’ll keep an eye out on the docs for possible updates.

1 Like

Thank you for the update here. Truthfully, that approach might be the fastest and simplest way to accommodate for the time zone change. However, yes, if we ever do implement an update, it would be placed in our Docs. Thanks!

I have to say this is the first time since using Netlify we have gone through Daylight savings time. Not being able to set the timezone for scheduled functions is pretty ridiculous.

Now to fix this we have to go through 20+ repositories and manually change every script twice per year and re-deploy everything. I, wrongly , presumed that scheduled functions would run based on the timezone set in our account. In fact the view on the scheduled function page even goes to the trouble to tell us that our scheduled function won’t run when we want it to. :pensive:

I don’t believe this is an edge case at all. All other scheduled cron systems have the ability to do this by setting environment variables or passing a timezone to the function setting up the job.

It’s literally the second code sample shown for firebase functions.

@vultuk as a fellow Netlify user, I feel compelled to respond to your message, because it really bothered me. Everyone gets frustrated, and I’ve had my share with Netlify, but I imagine your attitude isn’t helping things nor inspiring the Netlify team to want to help you.

Some of my thoughts:

  1. You’re comparing Firebase, which is a full-featured backend toolkit funded/operated by Google… and Netlify’s (which is primarily a front-end build and hosting service) “Scheduled Functions” service which is in BETA and clearly indicated as such. Calling the difference between their feature sets “ridiculous” is something I find really unfair, and again, demotivating.

  2. Your complaint that you have to go through 20+ repositories and manually change every script etc. sounds like you implemented/deployed a feature without understanding how it would work. Blaming Netlify for your lack of rigor in implementing something you didn’t fully understand is misplacing your anger.

  3. There are plenty of solutions other than changing every script twice per year… that IS ridiculous.

Here’s a one-liner example you can use to only run your script at 9 AM Los Angeles TZ:

[ "$(TZ=America/Los_Angeles date +%H)" -eq 9 ] && echo "Problem solved"

Run this command every hour and it’ll only trigger when it’s the right time.

Even better, use environmental variables for both timezone and time, so you can update it without leaving the netlify GUI :slight_smile:

P.S. I have spent 4 years dealing with this stuff because I coordinate scheduled push notifications to users in 16 different offsets on earth… so I get the frustrations in dealing with this, and wanting things to ‘just work’. I’m replying here because I think part of being a member of a community means staying positive and finding solutions.

In any case, I wish you the best on your project - and a great day.