0

クォーツ初心者です。

私は単純に、開始日 (おそらく過去)、終了日、および間隔を指定して、Quartz.net が正しい日付の発生を計算できるかどうかを調べようとしています - これは Quartz の主な使用例ではないかもしれませんが、 API について私が発見できること。

したがって、このフラグメントを考えると:

var exp = new CronExpression("0 0 0 1/7 * ? *");

    var next = exp.GetNextValidTimeAfter(new DateTime(2012, 1, 1, 12, 30, 00).ToUniversalTime());
    while (next < DateTime.Parse("30 Oct 2012"))
    {
        next = exp.GetNextValidTimeAfter(next.Value);
        System.Diagnostics.Debug.WriteLine(next);
    }

結果は次のように表示されます (切り捨てられます):

14/01/2012 11:00:00 午前 +00:00

2012/01/21 11:00:00 午前 +00:00

2012/01/28 11:00:00 午前 +00:00

2012/01/31 11:00:00 午前 +00:00

2012 年 7 月 2 日 11:00:00 午前 +00:00

14/02/2012 11:00:00 午前 +00:00

2012/02/21 午前 11:00:00 +00:00

2012/02/28 午前 11:00:00 +00:00

29/02/2012 11:00:00 午前 +00:00

2012 年 7 月 3 日 11:00:00 午前 +00:00

Errr...Quartz の CRON 式には常に月の最終日が含まれており、基本的にそこから次の日付を計算しているようです。または、クオーツ/クロンに対する私の期待/理解は間違っていますか?

また、これらの結果はhttp://www.cronmaker.com/を使用してバックアップされているようです...

ありがとう!

4

1 に答える 1

1

cron 式で探しているものを達成できないとは思いません。

Quartz.Net 2.xをダウンロードして使用すると、 CalendarIntervalTriggerと呼ばれる新しいタイプのトリガーを使用して、さまざまな間隔単位を管理できます。

このコードをテストしたところ、期待どおりに動作します。

DateTimeOffset startCalendar = DateBuilder.DateOf(11, 0, 0, 14, 1, 2012);

var weeklyTrigger = new CalendarIntervalTriggerImpl
{
    StartTimeUtc = startCalendar,
    RepeatIntervalUnit = IntervalUnit.Week,
    RepeatInterval = 1  // every one week;
};

IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(weeklyTrigger, null, 10);

foreach (var item in fireTimes)
{
    Console.WriteLine(item);
}
Console.ReadLine();

結果:

14/01/2012 11:00:00 +00:00
21/01/2012 11:00:00 +00:00
28/01/2012 11:00:00 +00:00
04/02/2012 11:00 :00 +00:00
11/02/2012 11:00:00 +00:00
18/02/2012 11:00:00 +00:00
25/02/2012 11:00:00 +00:00
03/ 2012 年 3 月 11:00:00 +00:00
2012 年 10 月 3 日 11:00:00 +00:00
2012 年 3 月 17 日 11:00:00 +00:00

于 2012-08-29T23:13:38.787 に答える