0

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?

Leah
  • 25
  • 8
  • Is it for the last day of the month or 28th in FEB and 30 in all other? – Anil Parshi Oct 07 '21 at 06:16
  • 28th in FEB and 30 in all other – Leah Oct 07 '21 at 06:22
  • I'm not sure this is possible with one expression since you'd need to use an "xor" construct. You could try 2 expressions: 1 for the last day of Feb (using `L`) and one for 30th of every month except Feb. – Thomas Oct 07 '21 at 07:53

1 Answers1

0

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

Anil Parshi
  • 875
  • 5
  • 21