public static DateTimeOffset?GetNextFireTime(this SnapshotRule rule, DateTimeOffset from) { ICalendar calendar = rule.GetCalendar(); CronExpression cron = new CronExpression(rule.GeneratedCron); DateTimeOffset?it = from; do { it = cron.GetNextValidTimeAfter(it.Value); if (it.HasValue) { if (calendar != null && !calendar.IsTimeIncluded(it.Value)) { continue; } return(it.Value); } else { return(null); } } while (true); }
public static int GetFireCountBetween(this SnapshotRule rule, DateTimeOffset from, DateTimeOffset to, CancellationToken cancel) { int count = 0; ICalendar calendar = rule.GetCalendar(); CronExpression cron = new CronExpression(rule.GeneratedCron); DateTimeOffset?it = from; do { it = cron.GetNextValidTimeAfter(it.Value); if (it.HasValue) { if (calendar != null && !calendar.IsTimeIncluded(it.Value)) { continue; } else if (it.Value > to) { break; } count++; } else { break; } } while (cancel == null || cancel.IsCancellationRequested == false); return(count); }