Skip to content
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

Upper bound at 31-12-2498 22:59:00? #75

Closed
DevJasperNL opened this issue Mar 4, 2025 · 3 comments
Closed

Upper bound at 31-12-2498 22:59:00? #75

DevJasperNL opened this issue Mar 4, 2025 · 3 comments

Comments

@DevJasperNL
Copy link
Contributor

While trying to reproduce #73 I noticed something else: Cronos stops working past the UTC time 31-12-2498 22:59:00.

Reproduction code:

CronExpression expression = CronExpression.Parse("* * * * *");
var fromUtc = DateTime.SpecifyKind(new DateTime(2497, 12, 25), DateTimeKind.Utc);

for (var i = 0; i < 1000000; i++)
{
    var result = expression.GetNextOccurrence(fromUtc, TimeZoneInfo.Local);
    if (result == null)
    {
        throw new InvalidOperationException($"No result for input {fromUtc}");
    }
    fromUtc = result.Value;
}

Exception is thrown with message No result for input 31-12-2498 22:59:00

Not sure if this is by design, I couldn't find anything for it.
I would have expected it to continue working up to DateTime.MaxValue. It seems like it works to about 1/4 of that.

@DevJasperNL
Copy link
Contributor Author

Just tested this in NCrontab as well. It goes all the way to DateTime.MaxValue.

@DevJasperNL
Copy link
Contributor Author

Closing as this looks like it is by design.
Saw int MaxYear = 2499; in CronExpression

@odinserj
Copy link
Member

The year limit was introduced to avoid looping through 9999 year for unreachable cron expressions (as they can be more difficult than 30th of February). I have another idea to solve this problem though – to set a relative limitation, and not the absolute one. For example, we can limit the GetOccurrence method to stop iterations when nothing was found within the 100 years, starting from the from date. What do you think about this solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants