atifaziz / NCrontab

Crontab for .NET
Apache License 2.0
913 stars 139 forks source link

Expression of 30th/31th february throws ArgumentOutOfRangeException #106

Open LuckyyyStrike opened 1 year ago

LuckyyyStrike commented 1 year ago

Steps to reproduce

Call GetNextOccurence() on a parsed expression of this format: "0 0 30 2 *"

Description

Obviously the 30th/31th february does not exist. Why does this expression even parse succcessfully, when an expression like "0 0 32 " does not?

atifaziz commented 1 year ago

Why does this expression even parse succcessfully

Because it's valid per the expression rules. The rule says the day field can go from 1 to 31 irrespective of the month or the other fields. Thing is, if you have an expression like 0 0 30 1-6 * that says midnight on the 30th of the first 6 months then February will be skipped.

LuckyyyStrike commented 1 year ago

Why does this expression even parse succcessfully

Because it's valid per the expression rules. The rule says the day field can go from 1 to 31 irrespective of the month or the other fields. Thing is, if you have an expression like 0 0 30 1-6 * that says midnight on the 30th of the first 6 months then February will be skipped.

Makes sense

Issue 21 talks about the same problem that occurs here. There, the issue was resolved by returning the endDate argument when calling GetNextOccurences. Wouldn't it make sense to do the same here?