Business Hours Only
What it does: Blocks events that occur outside of Monday-Friday, 9 AM to 5 PM, so only business-hours meetings appear in the synced calendar.
Use case: Keep a shared availability calendar clean by excluding early-morning calls, late-night events, and weekend personal commitments.
function rule(event: RuleEvent): RuleResult {
if (!event.isWeekday) {
return { pass: false, reason: 'Event is on a weekend' };
}
if (event.hour < 9 || event.hour >= 17) {
return { pass: false, reason: 'Event is outside business hours' };
}
return { pass: true };
}
hour and isWeekday are evaluated in UTC, not your local timezone. The bounds above describe a 9-to-5 day in UTC — shift them by your UTC offset for your local business hours. For example, 9 AM–5 PM Eastern (UTC-5) is event.hour >= 14 && event.hour < 22. Note that the offset changes with daylight saving time, so you may need to adjust the bounds twice a year — or use overlapsTimeOfDay(), which takes local times and a time zone and handles the switch for you.
How It Works
Two RuleEvent computed properties power this recipe:
isWeekday—truewhen the event starts on Monday through Friday (in UTC)hour— the hour of day (0–23) when the event starts (in UTC)
Checking isWeekday first eliminates all weekend events. Then checking hour filters events that start before 9 AM or at 5 PM or later. All-day events have hour set to 0, so they will be blocked unless you add an exception.
Customization
Extend hours to 8 AM – 6 PM:
function rule(event: RuleEvent): RuleResult {
if (!event.isWeekday) {
return { pass: false, reason: 'Event is on a weekend' };
}
if (event.hour < 8 || event.hour >= 18) {
return { pass: false, reason: 'Event is outside extended business hours' };
}
return { pass: true };
}
Allow Saturday morning events (e.g. 9 AM – 12 PM):
function rule(event: RuleEvent): RuleResult {
const isSaturdayMorning =
event.dayOfWeek === 6 && event.hour >= 9 && event.hour < 12;
if (!event.isWeekday && !isSaturdayMorning) {
return { pass: false, reason: 'Event outside allowed schedule' };
}
if (event.isWeekday && (event.hour < 9 || event.hour >= 17)) {
return { pass: false, reason: 'Event outside business hours' };
}
return { pass: true };
}
Always pass all-day events regardless of the day:
function rule(event: RuleEvent): RuleResult {
if (event.isAllDay) {
return { pass: true };
}
if (!event.isWeekday) {
return { pass: false, reason: 'Event is on a weekend' };
}
if (event.hour < 9 || event.hour >= 17) {
return { pass: false, reason: 'Event is outside business hours' };
}
return { pass: true };
}
Related Recipes
- Filter by Duration -- Filter events based on meeting length