Quartz.NET seems to not work correctly with days of week

55 Views Asked by At

I am only using CronExpression at this time. Let's suppose I have the following expression: 0 35 09 ? * 2 This should mean (https://crontab.cronhub.io/):

enter image description here

And this is what I want.

Now let's try with some timestamp: 2024.02.06 09:35:00. As far as I know, today is Tuesday. The time should match also.

var dto = DateTimeOffset.Parse("2024.02.06 09:35:00");

dto.Dump(dto.DayOfWeek.ToString());
var co2 = new CronExpression("0 35 09 ? * 2");
co2.IsSatisfiedBy(dto).Dump();

The result:

enter image description here

But:

var co3 = new CronExpression("0 35 09 ? * 3");
co3.IsSatisfiedBy(dto).Dump("0 35 09 ? * 3");

Yields:

enter image description here

This means that it satisfies a pattern that has Wednesday in it.

On the other hand:

var next = co2.GetNextValidTimeAfter(dto);
next.Dump($"{next.Value.DayOfWeek}");
co2.IsSatisfiedBy(next.Value).Dump();

Yields:

enter image description here

And that is also confusing as, the pattern 0 35 09 ? * 1, that has Monday in is not satisfied.

Am I doing something wrong here, or there is a bug in Quartz.Net?

[Update]

It is a bug. For anybody interested, Fix PR-ed: https://github.com/quartznet/quartznet/pull/2274

[Update 2] "It's not a bug, it's a feature". For whatever reason the author(s) of Quartz.NET have chosen to go against the Cron "standard" of DOW 1-7 meaning MON-SUN, by implementing 1-7 to be SUN-SAT. Breaking any potential compatibility with standard tools. Hence my PR would break this break...

0

There are 0 best solutions below