Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Skip Holidays in .NET Scheduled Jobs with NaturalCron Custom Keywords

说明与用途

在 .NET 中,NaturalCron 允许定义自定义关键字(如 "holiday"),并在 cron 表达式中使用,以自动跳过周末和节假日。

问题

Cron expressions cannot express holiday exclusions, forcing jobs to check dates in code and leading to inconsistent schedules.

结果

The job now schedules only on business days, automatically skipping weekends and defined holidays, with the schedule itself documenting the exclusions.

工作流

  • 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

证据

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.

来源

  • 记录日期: 2026-10-14T04:41:31.583Z