Skip to content

Commit b1456e5

Browse files
committed
DST awareness.
1 parent b916bd1 commit b1456e5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export async function helloLunchChannel(request: HttpRequest, context: Invocatio
1010
}
1111

1212
export async function helloLunchChannelInternal() {
13+
// Check if we should run based on Finnish time
14+
const now = new Date();
15+
const finnishTime = new Date(now.toLocaleString('en-US', { timeZone: 'Europe/Helsinki' }));
16+
const targetHour = 10;
17+
const targetMinute = 30;
18+
19+
if (finnishTime.getHours() !== targetHour || finnishTime.getMinutes() !== targetMinute) {
20+
return { body: 'Not the correct Finnish time to run' };
21+
}
22+
1323
const slackUrl = process.env.SlackWebHookURL || '';
1424
const restaurantUrl = process.env.RestaurantMenuURL || '';
1525
const openAiUrl = process.env.OPENAI_API_URL || ''
@@ -32,10 +42,9 @@ export async function timerTrigger1(myTimer: Timer, context: InvocationContext):
3242
return await helloLunchChannelInternal();
3343
}
3444

35-
// Scheduling for 10:30 AM on weekdays, but cloud functions are UTC
36-
// so 7:30 AM for Finnish summertime and 8:30 AM for Finnish wintertime
45+
// Schedule to run at both 7:30 UTC and 8:30 UTC on weekdays to catch 10:30 Finnish time in both DST and non-DST periods
3746
app.timer('timerTrigger1', {
38-
schedule: '0 30 8 * * 1-5',
47+
schedule: '0 30 7,8 * * 1-5',
3948
handler: timerTrigger1,
4049
});
4150

0 commit comments

Comments
 (0)