A fully-featured .NET library for working with Cron expressions. Built with time zones in mind and intuitively handles daylight saving time transitions
MIT License
1.01k
stars
118
forks
source link
Sometimes GetNextOccurrence returns a past occurrence (but very close to now) #73
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) ?
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.
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.TimerMost 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) ?