Start date equal to end date will give back no sequence?
MichaelSchofeld opened this issue · comments
If i supply a start-date Feb 11, 1pm and an end-date Feb 11, 2 pm. and I say i want all occurrences that fall on Tuesdays in this date range.. Feb 11 is a Tuesday so should it not return 1 occurrence?
Just wondering if this is a bug or by design?
As per the documentation, start/base and end date and time are exclusive:
NCrontab/NCrontab/CrontabSchedule.cs
Lines 171 to 178 in b6659e4
So this is by-design assuming your crontab expression was hourly on Tuesdays; that is 0 * * * Tue
. If you had something like this (every 15 minutes of a Tuesday ):
var schedule = CrontabSchedule.Parse("*/15 * * * Tue");
var occurrences = schedule.GetNextOccurrences(new DateTime(2020, 2, 11, 1, 0, 0),
new DateTime(2020, 2, 11, 2, 0, 0));
foreach (var dt in occurrences)
Console.WriteLine(dt.ToString("ddd, dd MMM yyyy HH:mm"));
then you should see 3 occurrences:
Tue, 11 Feb 2020 01:15
Tue, 11 Feb 2020 01:30
Tue, 11 Feb 2020 01:45
Note that 1 am and 2 am do not occur. If you wanted those, you'd have to adjust start and end by a second:
var schedule = CrontabSchedule.Parse("*/15 * * * Tue");
var start = new DateTime(2020, 2, 11, 1, 0, 0);
var end = start.AddHours(1);
var occurrences = schedule.GetNextOccurrences(start.AddSeconds(-1), end.AddSeconds(1));
foreach (var dt in occurrences)
Console.WriteLine(dt.ToString("ddd, dd MMM yyyy HH:mm"));
Closing as by-design.