using System; using System.Collections.Generic; using Quartz; namespace CRMBLL.Task { // GB4 parity: CommonFunctionFrameDAL.GetNextOccurrence — walks a CRON expression // forward from startDate, collecting each fire time up to (and excluding) endDate. // Used by TaskBLL.GenerateTask to compute which dates need a recurring task generated. public static class CronOccurrenceCalculator { private const int MaxIterations = 10000; public static List GetNextOccurrences(string cronExpression, DateTime startDate, DateTime endDate) { var occurrences = new List(); var schedule = new CronExpression(cronExpression); var cursor = new DateTimeOffset(startDate); for (int i = 0; i < MaxIterations; i++) { DateTimeOffset? nextFire = schedule.GetNextValidTimeAfter(cursor); if (nextFire == null) break; DateTime nextDate = nextFire.Value.LocalDateTime; if (nextDate > endDate) break; occurrences.Add(nextDate); cursor = nextFire.Value; } return occurrences; } } }