Search code examples
cronapache-camelquartz-schedulerquartz

How to create my own calendar instead of excluding date like holiday calendar in quartz scheduler


I want to create my own calendar example: In a month, i can have 33 days and 53 weeks in a year.


Solution

  • You only need to implement the Quartz Calendar interface or extends Quartz BaseCalendar class and implement/override getNextIncludedTime and isTimeIncluded methods. Then you simply register the new calendar implementation with Quartz by invoking scheduler.addCalendar(name, new YourCalendar(), true, true). From now on you can have your triggers refer to your custom calendar to exclude whatever dates/daytimes you want.