问题
Starting from the Jan 1st 2014 the 2 week periods yield the following schedule:
- Jan 14
- Jan 28
- Feb 11
- Feb 25
- Mar 11
- Mar 25
- Apr 8
- Apr 22
- May 6
- May 20
etc ...
This is not an idle question. Some companies have exactly 2 week long pay periods, meaning they have 26 pay periods per year rather than 24 for a company that pays twice a month as opposed to every two weeks exactly. I want to know whether I can express the pay schedule of such a company using a CRON expression.
Finally, it is possible that no CRON expression can be used to express what I want, but the Quartz scheduler may have some tricky solution that can ultimately produce the needed schedule. Note, that I can always create a calendar scheduler with 26 explicit triggers - one per pay period. I am not talking about this kind of solution.
I am using the .NET port of the Quartz library.
EDIT
An equally good schedule would be exactly every other Sunday. Note, it is not equivalent to every 2nd and 4th Sunday. Indeed, if a month has 5 Sundays, then the first schedule may result in three instances for that particular month, if started from the first Sunday. Whereas the second schedule always yields exactly two instances per month.
I have a feeling such schedules cannot be expressed in CRON, because they carry over from month to month, whereas CRON resets its month trigger each time a new month starts.
EDIT2
I guess what I am looking for could be expressed by an imaginary DayOfYear CRON field. Helas, no such thing exists. But then again, I could be wrong.
回答1:
If you're using version 2.0 then you can use the CalendarIntervalTrigger, set the RepeatIntervalUnit to weeks and the RepeatInteval to 2 so that it fires every 2 weeks.
来源:https://stackoverflow.com/questions/21633029/is-it-possible-to-express-2-week-periods-as-a-cron-expression-as-implemented-by