Is it possible to express 2 week periods as a CRON expression as implemented by Quartz?

别来无恙 提交于 2019-12-13 06:27:18

问题


Starting from the Jan 1st 2014 the 2 week periods yield the following schedule:

  1. Jan 14
  2. Jan 28
  3. Feb 11
  4. Feb 25
  5. Mar 11
  6. Mar 25
  7. Apr 8
  8. Apr 22
  9. May 6
  10. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!