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

Sometimes GetNextOccurrence returns a past occurrence (but very close to now) #73

Open
Foudge opened this issue Jun 28, 2024 · 1 comment
Labels

Comments

@Foudge
Copy link

Foudge commented Jun 28, 2024

Hi, here my simplified code :

CronExpression expression = CronExpression.Parse("0 4 * * *");
DateTimeOffset now = DateTimeOffset.Now;
DateTimeOffset? next = _cronInfo.Expression.GetNextOccurrence(now, TimeZoneInfo.Local);
if (next.HasValue)
_timer.Interval = (next.Value - now).TotalMilliseconds; //_timer is System.Timers.Timer

Most of the time, it's ok, but sometimes I have System.ArgumentException because of an invalid interval value:
System.ArgumentException: Invalid value '-0,0091' for parameter 'interval'.
System.ArgumentException: Invalid value '-0,0006' for parameter 'interval'.
System.ArgumentException: Invalid value '-0,0037' for parameter 'interval'.
I's always a negative value very close to zero !

I found a way around, but I was wondering how it was possible to have a negative value (i.e. earlier than the date given as parameter) ?

@odinserj odinserj added the bug label Sep 11, 2024
@odinserj
Copy link
Member

Thanks for reporting this. This is a bug, since it's not expected that next execution will be less than the given one. Trying to reproduce the behavior.

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

No branches or pull requests

2 participants