Пример #1
0
        public IEnumerable<DateTime> CalculateRecurrenceSet(int? skip = 0, int take = int.MaxValue,
            DateTimeWindow dateTimeWindow = null)
        {
            // if dateTimeWindow wasn't passed; default is all time
            dateTimeWindow = dateTimeWindow ?? DateTimeWindow.AllTime;
            var recurrenceSet = new List<DateTime>();
            DateTime precedingOccurrence = StartDateTime;
            DateTime nextOccurrence;

            // handle skipping a number of occurrences into the complete recurrence set
            if (skip > 0)
            {
                // initialize to 1 because StartDateTime is used to initialize precedingOccurrence
                int skipCount = 1;
                while (skipCount != skip)
                {
                    if (TryCalculateNextOccurrence(precedingOccurrence, dateTimeWindow, out nextOccurrence))
                    {
                        precedingOccurrence = nextOccurrence;
                        skipCount++;
                    }
                        // handle skipping more results than the number of results which exist
                    else
                    {
                        return recurrenceSet;
                    }
                }
            }
            else if (dateTimeWindow.MinimumIncludedDateTime < StartDateTime)
            {
                recurrenceSet.Add(StartDateTime);
            }

            while (TryCalculateNextOccurrence(precedingOccurrence, dateTimeWindow, out nextOccurrence))
            {
                precedingOccurrence = nextOccurrence;
                recurrenceSet.Add(nextOccurrence);
                // handle taking only a subset of the complete recurrence set
                if (recurrenceSet.Count == take)
                {
                    break;
                }
            }
            return recurrenceSet;
        }
Пример #2
0
 public bool TryCalculateNextOccurrence(DateTime precedingOccurrence, DateTimeWindow dateTimeWindow,
     out DateTime nextOccurrence)
 {
     DateTime nextDateTimeCandidate = GetDateTimeOfNextOccurrenceCandidate(precedingOccurrence);
     while (!IsDateTimeAfterEndDateTime(nextDateTimeCandidate) &&
            !IsDateTimeAfterDateTimeWindow(nextDateTimeCandidate, dateTimeWindow))
     {
         if (!IsDateExcluded(nextDateTimeCandidate) &&
             !IsDateTimeBeforeDateTimeWindow(nextDateTimeCandidate, dateTimeWindow))
         {
             nextOccurrence = nextDateTimeCandidate;
             return true;
         }
         nextDateTimeCandidate = GetDateTimeOfNextOccurrenceCandidate(nextDateTimeCandidate);
     }
     nextOccurrence = default(DateTime);
     return false;
 }
Пример #3
0
 private bool IsDateTimeAfterDateTimeWindow(DateTime dateTime, DateTimeWindow dateTimeWindow)
 {
     return dateTimeWindow.MaximumIncludedDateTime < dateTime;
 }
Пример #4
0
 private bool IsDateTimeBeforeDateTimeWindow(DateTime dateTime, DateTimeWindow dateTimeWindow)
 {
     return dateTimeWindow.MinimumIncludedDateTime > dateTime;
 }