I'm trying to write a cron expression for quartz scheduler.
The requirement is that in case the day of month does not exists (like 30)- the job will run at the closest day instead.
For example: on February it will run on 28 but on November- on 30.
I saw the answer here: quartz-cron-what-if-the-day-of-month-does-not-exist but is there any better way to perform it?
My approach for this would be,
Running a CRON for the 3 days of every month starting from 28.
which are 28,29,30 (29 for Leap year if needed)
and put a condition in the program to find out if the month is February and perform the actions accordingly,
Cron Expression for that would be,
00 00 28,29,30 * *
Here is the logic:
if the month is Feb {
check if Date is last date of the month
{
perform required action
}
}
else if the date is 30th of month
{
perform required action
}
Hope this helps, Since I don't work with Java I have given just the logic