Skip to content

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

@Foudge

Description

@Foudge

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) ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions