Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this cronExpression correct?

I don't know if the below expression is correct:

<property name="cronExpression" value="0  0  12  2  *  MON-FRI ?"/> 

I try to configure my trigger to fire every second day of every month, no matter the year, at noon, and the day of week has to be between Monday and Friday.

I'd really appreciate if someone could help me. Thanks in advance.

like image 633
eliz Avatar asked Dec 15 '10 23:12

eliz


2 Answers

I'm assuming you meant "every second day (every other day), as long as it's MON-FRI".

According to Quartz CronTrigger Tutorial:

'1/3' in the day-of-month field means "fire every 3 days starting on the first day of the month".

So, 1/2 would mean "fire every second day starting on the first day of the month". A cronExpression like 0 0 12 1/2 * MON-FRI * should then be close to what you want. Checking with

org.quartz.CronExpression.isValidExpression("0  0  12  1/2 * MON-FRI *")

...says that the expression is valid.

However, testing it a little further with:

CronExpression e = new CronExpression("0  0  12  1/2 * MON-FRI *");
e.isSatisfiedBy(new DateTime(2012, 9, 26, 12, 0, 0, 0).toDate());

...throws an exception:

> Exception in thread "main" java.lang.UnsupportedOperationException:
> Support for specifying both a day-of-week AND a day-of-month parameter
> is not implemented.

So, seems like jhouse is right and you just can't do that with a cronExpression.

Maybe something like this would work as a workaround: Quartz cron expression for cron triggers executed every Nth Hour/Day/Week/Month

like image 98
Jonik Avatar answered Sep 25 '22 21:09

Jonik


You cannot specify both a day of month and a day of week - it is not supported.

like image 38
jhouse Avatar answered Sep 24 '22 21:09

jhouse