是否可以将2周的周期表示为由Quartz实现的CRON表达式? [英] Is it possible to express 2 week periods as a CRON expression as implemented by Quartz?

查看:737
本文介绍了是否可以将2周的周期表示为由Quartz实现的CRON表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自2014年1月1日起,2周的周期会产生以下时间表:


  1. 1月14日

  2. 1月28日

  3. 2月11日

  4. 2月25日

  5. 3月11日
  6. $ b
  7. 3月25日

  8. 4月8日

  9. 4月22日


  10. 5月20日

等...



这不是一个空闲的问题。一些公司的工资周期恰好为2周,这意味着他们每年有26个工资周期,而不是每月支付两次的公司,而不是每两周一次。我想知道我是否可以使用CRON表达式表达这样的公司的工资表。



最后,可能没有CRON表达式可以用来表达什么我想,但Quartz调度程序可能有一些棘手的解决方案,最终可以产生所需的计划。注意,我总是可以创建一个日历调度程序,有26个显式触发器 - 每个付费周期一个。我不是在谈论这种解决方案。



我正在使用Quartz库的.NET端口。



EDIT



同样好的时间表会几乎每隔一个星期日。请注意,它不等同于每第2和第4个星期日。实际上,如果一个月具有5个星期日,则第一时间表可以导致该特定月份的三个实例,如果从第一个星期日开始。而第二个计划总是每月产生正好两个实例。



我有一种感觉,这样的计划不能在CRON中表达,因为它们从一个月到另一个月,而CRON



EDIT2

猜猜我在寻找什么可以通过虚拟 DayOfYear CRON字段表示。赫拉斯,没有这样的事情存在。

解决方案

如果您使用的是2.0版,那么您可以使用 CalendarIntervalTrigger ,请设置 RepeatIntervalUnit 更改为周,将RepeatInteval更改为2,以便它每2周发射一次。


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.

解决方案

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.

这篇关于是否可以将2周的周期表示为由Quartz实现的CRON表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆