Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions email-notifications/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ export default {
async scheduled(_event, env, _ctx): Promise<void> {
console.log(`${formatDateTime(new Date())}:`);

// 1. Query for events starting the next day
// e.g. whose start_time is within 00:00 and 23:59 of the next day
const tmrStart = new Date(Date.now() + 24 * 60 * 60 * 1000);
const tmrEnd = new Date(tmrStart.getTime() + 23 * 60 * 60 * 1000);
// 1a. Query for events starting the next day
// e.g. whose start date (derived from start_time) is tomorrow
const tmrStart = new Date();
tmrStart.setDate(tmrStart.getDate() + 1);
tmrStart.setHours(0, 0, 0, 0);

const tmrEnd = new Date(tmrStart);
tmrEnd.setHours(23, 59, 59, 999);

const { data: events } = await supabase
.from('community_events')
.select('*, event_tickets(email)')
Expand All @@ -27,7 +32,7 @@ export default {
// 1c. Log events found to happen tomorrow
console.log(`- Found ${events.length} event(s) starting tomorrow:`);
for (const event of events) {
console.log(` - ${event.title} (${event.start_time})`);
console.log(` - ${event.title} (${formatDateTime(event.start_time)})`);
}

// 2. Construct email notification
Expand Down
1 change: 1 addition & 0 deletions email-notifications/src/templates/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function formatDateTime(datetime: string | Date) {
hour: "2-digit",
minute: "2-digit",
hour12: false,
timeZone: "Antarctica/Davis",
timeZoneName: "shortOffset",
});
}
Loading