/// <summary> /// Move to the next element /// </summary> /// <returns>Returns true if not at the end, false if it is</returns> public bool MoveNext() { bool hasMore = true; // First time through? if (dates == null) { // If it's got a count, generate them all as we can't do it by yearly ranges. There shouldn't be // too many although it's possible. if (recurrence.MaximumOccurrences != 0) { dates = recurrence.InstancesBetween(start, DateTime.MaxValue); } else { // If it's got an end date, we'll generate instances in one year increments. This should be // more efficient for long running or never ending sequences. end = start.AddYears(1).AddSeconds(-1); dates = recurrence.InstancesBetween(start, end); } } else { idx++; } if (idx >= dates.Count) { // If it uses a count, we got them all on the first call so stop now if (recurrence.MaximumOccurrences != 0) { hasMore = false; } else { idx = 0; // Advance one year at a time until we get something or the end date is reached do { if (start.Year < DateTime.MaxValue.Year) { start = end.AddSeconds(1); if (start > recurrence.RecurUntil) { hasMore = false; break; } } else { hasMore = false; break; } if (start.Year < DateTime.MaxValue.Year) { end = start.AddYears(1).AddSeconds(-1); } else { end = new DateTime(DateTime.MaxValue.Year, 12, 31, 23, 59, 59); } dates = recurrence.InstancesBetween(start, end); } while(dates.Count == 0); } } return(hasMore); }
/// <summary> /// Reset the enumerator to the start /// </summary> public void Reset() { idx = 0; start = recurrence.StartDateTime; dates = null; }