HangfireIO / HangfireIO/Cronos
GetNextOccurrence based on today's date
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 137
- Avg merge
- 5d 11h
- Merged PRs (30d)
- 1
Description
Hi. I have a problem getting next occurrence time or i just miss something in Cronos documentation.
Problem:
User can set scheduler, which is done with the cron expression. User can set date and time and interval. For example 1.2.2012 15:00:00 every two days. But the date doesn't change often, only when user set new time or interval, what means if today is 20.2.2012 12:00:00, then GetNextOccurrence() get the 3.2.2012 15:00:00 as result, but i want to get 21.2.2012, which is the next relevant run time.
Workaround:
```var expression = CronExpression.Parse(cronExpr, CronFormat.IncludeSeconds);
var occs = expression.GetOccurrences(schedule.Time, DateTime.UtcNow, TimeZoneInfo.Local).ToList();
job.NextRunTime = expression.GetNextOccurrence(occs.Last(), TimeZoneInfo.Local);
```
I just get all occurrences till today and then i use last one to get the ACTUAL next one.
Does it make sense to have a function like: GetNextOccurrenceBasedOnDateTimeNow(...)?
Thank You
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.