-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ranges that cross over midnight #24
Comments
As pointed out in #14, this won't work. In fact, I should disallow inverted ranges and throw an error instead to avoid confusion. You can also see on crontab.guru that Your best bet to get the result you want is to create two schedules, one that goes from hour 20 to 23 and another from 0 to 4. You can then use var bt = new DateTime(2000, 12, 4);
var et = bt.AddDays(2);
var s1 = NCrontab.CrontabSchedule.Parse("0 20-23 * * *");
var o1 = s1.GetNextOccurrences(bt, et);
var s2 = NCrontab.CrontabSchedule.Parse("0 0-4 * * *");
var o2 = s2.GetNextOccurrences(bt, et);
var ms =
o1.SortedMerge(OrderByDirection.Ascending, o2)
.DistinctUntilChanged();
foreach (var dt in ms)
Console.WriteLine(dt);
|
I'm going to close this because the behaviour is by-design. The right fix is to disallow such an expression to avoid confusion and which is now being tracked as issue #25. |
Hello,
I would like to report an unexpected behavior.
Cron:
* 20-4 * * *
I expect it to work as if written:
* 20,21,22,...,3,4 * * *
it works as if written:
* 4,5,6,...,19,20 * * *
I believe
20-4
should expand to20-23,0-4
rather than4-20
. since it makes little sense to write the numbers backwards. the original crontab considers midnight crossing ranges as invalid so either case is violating the original implantation, might as well implant the one that makes more sense.I know that this was mentioned before in #14, but there was no alternatives proposed there.
The text was updated successfully, but these errors were encountered: