Closed leafduan closed 6 years ago
Cron expressions are never calculated based on the current time, so May 21, 2018
date will always match the 0 8 */5 * *
expression, regardless you are asking to get ones since May 1, May 3, May 13, etc. You can consider Cron expressions as regular expressions, but for date/time values: their output is stable.
Simply speaking, every cron parsing algorithm looks like the following loop:
var data = startDate;
while (date < endDate)
{
if (IsMatch(date, cronExpression))
{
yield return date;
}
date = date.AddSeconds(1); // Or minutes
}
And if you need to get occurrences every 3 days or so, the best term is to make your own loop and use the DateTime.AddDays
method instead.
Hi odinserj,
Thank you for your comment.
And I catch the same idea with you, override the get occurrences loop, using DateTime.AddDays
instead.
I want to run a job every three or five (or n) days from now, and I wrote the expression '0 8 /5 *'.
If now is '2018/05/17',
and I get the occurrences:
but, which I expected are:
Do the cron expression that I wrote is wrong? Or the Cronos don't support this situation?
Any one help me?
Thanks, Leaf