Skip Holidays in .NET Scheduled Jobs with NaturalCron Custom Keywords
Description and use
In .NET, NaturalCron lets you define custom keywords like "holiday" and use them in cron expressions to automatically skip weekends and holidays.
Problem
Cron expressions cannot express holiday exclusions, forcing jobs to check dates in code and leading to inconsistent schedules.
Outcome
The job now schedules only on business days, automatically skipping weekends and defined holidays, with the schedule itself documenting the exclusions.
Workflow
- Register holiday dates in a HashSet
- Configure NaturalCronCustomKeywords with AddMatchable("holiday", date => holidays.Contains(date.Date))
- Parse a cron expression that includes the custom keyword, e.g. "every day at 09:00:00 except [saturday, sunday, holiday]"
- Call GetNextOccurrences to get future run times
- Observe that holiday dates are skipped automatically
Evidence
With NaturalCron 1.1, you can finally teach your .NET jobs what a holiday is.
A schedule like “every weekday at 9, but not on holidays” is easy to say and hard to configure.
You register it once, at application startup
Christmas Day, the weekends and New Year’s Day are skipped, and the schedule itself says why.
- Record date: 2026-10-14T04:41:31.583Z