Closed ixm7 closed 4 months ago
You can use the GetOccurrences
method and pass DateTime.UtcNow
and DateTime.UtcNow.AddSeconds(X)
values there with the inclusive flag set, and return true
if there are any occurrences within the specified interval.
Thanks; I wasn't aware of that option.
This is similar to https://github.com/HangfireIO/Cronos/issues/58 but, instead of checking if now is a valid occurrence, the need is for a method to check if now is an active period.
Use case: a service has its own heartbeat for each task, but the user wants to specify active periods for some tasks (e.g. weekdays between 8 and 5). Outside that active period, the task should not run. The requested method should make it easy to determine if Now is an active vs inactive period. The method could have the following signature: Expression.IsActive(DateTime RefUtcDateTime, Integer ResolutionInSeconds)
If the RefUtcDateTime (typically it would be Now) is within the specified number of seconds from the next and previous occurrences, we are in an active period, and the method should return True.