/// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or
        /// Period from the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateExDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
        {
            // Handle EXDATEs
            if (Recurrable.ExceptionDates != null)
            {
                foreach (IPeriodList exdate in Recurrable.ExceptionDates)
                {
                    IEvaluator evaluator = exdate.GetService(typeof(IEvaluator)) as IEvaluator;
                    if (evaluator != null)
                    {
                        var periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, false);

                        Periods.ExceptWith(periods);

                        foreach (IPeriod p in periods)
                        {
                            // If no time was provided for the ExDate, then it excludes the entire day
                            if (!p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime))
                            {
                                p.MatchesDateOnly = true;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or Period from the Periods collection.
        /// </summary>
        /// <param name="referenceDate"></param>
        /// <param name="periodStart">The beginning date of the range to evaluate.</param>
        /// <param name="periodEnd">The end date of the range to evaluate.</param>
        virtual protected void EvaluateExDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
        {
            // Handle EXDATEs
            if (Recurrable.ExceptionDates == null)
            {
                return;
            }


            foreach (var exdate in Recurrable.ExceptionDates)
            {
                var evaluator = exdate.GetService(typeof(IEvaluator)) as IEvaluator;
                if (evaluator == null)
                {
                    continue;
                }

                var periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, false);
                foreach (var p in periods.Where(p => !p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime)))
                {
                    p.MatchesDateOnly = true;
                }
                Periods.ExceptWith(periods);
            }
        }
Example #3
0
        /// <summary>
        /// Evaulates the ExRule component, and excludes each specified DateTime from the Periods collection.
        /// </summary>
        /// <param name="referenceDate"></param>
        /// <param name="periodStart">The beginning date of the range to evaluate.</param>
        /// <param name="periodEnd">The end date of the range to evaluate.</param>
        protected virtual void EvaluateExRule(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
        {
            if (Recurrable.ExceptionRules == null)
            {
                return;
            }

            var excluded =
                Recurrable.ExceptionRules.Select(rule => rule.GetService(typeof(IEvaluator)) as IEvaluator)
                .Where(evaluator => evaluator != null)
                .SelectMany(evaluator => evaluator.Evaluate(referenceDate, periodStart, periodEnd, false))
                .ToList();

            Periods.ExceptWith(excluded);
        }
 /// <summary>
 /// Evaulates the ExRule component, and excludes each specified DateTime
 /// from the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 virtual protected void EvaluateExRule(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
 {
     // Handle EXRULEs
     if (Recurrable.ExceptionRules != null)
     {
         foreach (IRecurrencePattern exrule in Recurrable.ExceptionRules)
         {
             IEvaluator evaluator = exrule.GetService(typeof(IEvaluator)) as IEvaluator;
             if (evaluator != null)
             {
                 var periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, false);
                 Periods.ExceptWith(periods);
             }
         }
     }
 }
Example #5
0
        public override HashSet <Period> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
        {
            // Evaluate extra time periods, without re-evaluating ones that were already evaluated
            if ((EvaluationStartBounds == DateTime.MaxValue && EvaluationEndBounds == DateTime.MinValue) || periodEnd.Equals(EvaluationStartBounds) ||
                periodStart.Equals(EvaluationEndBounds))
            {
                //Exclusions take precedence over inclusions, so build the master set, then subtract the exclusions from it
                var rruleOccurrences = EvaluateRRule(referenceDate, periodStart, periodEnd, includeReferenceDateInResults);
                if (includeReferenceDateInResults)
                {
                    rruleOccurrences.UnionWith(new [] { new Period(referenceDate), });
                }

                var rdateOccurrences = EvaluateRDate(referenceDate, periodStart, periodEnd);

                var exRuleExclusions = EvaluateExRule(referenceDate, periodStart, periodEnd);
                var exDateExclusions = EvaluateExDate(referenceDate, periodStart, periodEnd);

                Periods.UnionWith(rruleOccurrences);
                Periods.UnionWith(rdateOccurrences);
                Periods.ExceptWith(exRuleExclusions);
                Periods.ExceptWith(exDateExclusions);

                if (EvaluationStartBounds == DateTime.MaxValue || EvaluationStartBounds > periodStart)
                {
                    EvaluationStartBounds = periodStart;
                }
                if (EvaluationEndBounds == DateTime.MinValue || EvaluationEndBounds < periodEnd)
                {
                    EvaluationEndBounds = periodEnd;
                }
            }
            else
            {
                if (EvaluationStartBounds != DateTime.MaxValue && periodStart < EvaluationStartBounds)
                {
                    Evaluate(referenceDate, periodStart, EvaluationStartBounds, includeReferenceDateInResults);
                }
                if (EvaluationEndBounds != DateTime.MinValue && periodEnd > EvaluationEndBounds)
                {
                    Evaluate(referenceDate, EvaluationEndBounds, periodEnd, includeReferenceDateInResults);
                }
            }

            return(Periods);
        }
Example #6
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or Period from the Periods collection.
        /// </summary>
        /// <param name="referenceDate"></param>
        /// <param name="periodStart">The beginning date of the range to evaluate.</param>
        /// <param name="periodEnd">The end date of the range to evaluate.</param>
        protected virtual void EvaluateExDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
        {
            if (Recurrable.ExceptionDates == null || !Recurrable.ExceptionDates.Any())
            {
                return;
            }

            var evaluator = Recurrable.ExceptionDates.First().GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator == null)
            {
                return;
            }

            var periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, true);

            Periods.ExceptWith(periods);
        }
Example #7
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or Period from the Periods collection.
        /// </summary>
        /// <param name="referenceDate"></param>
        /// <param name="periodStart">The beginning date of the range to evaluate.</param>
        /// <param name="periodEnd">The end date of the range to evaluate.</param>
        protected virtual void EvaluateExDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd)
        {
            if (Recurrable.ExceptionDates == null || !Recurrable.ExceptionDates.Any())
            {
                return;
            }

            var evaluator = Recurrable.ExceptionDates.First().GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator == null)
            {
                return;
            }

            var periods = evaluator.Evaluate(referenceDate, periodStart, periodEnd, false);

            foreach (var p in periods.Where(p => !p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime)))
            {
                p.MatchesDateOnly = true;
            }
            Periods.ExceptWith(periods);
        }
        public override HashSet <Period> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
        {
            Periods.Clear();

            var rruleOccurrences = EvaluateRRule(referenceDate, periodStart, periodEnd, includeReferenceDateInResults);

            //Only add referenceDate if there are no RecurrenceRules defined
            if (includeReferenceDateInResults && (Recurrable.RecurrenceRules == null || !Recurrable.RecurrenceRules.Any()))
            {
                rruleOccurrences.UnionWith(new[] { new Period(referenceDate), });
            }

            var rdateOccurrences = EvaluateRDate(referenceDate, periodStart, periodEnd);

            var exRuleExclusions = EvaluateExRule(referenceDate, periodStart, periodEnd);
            var exDateExclusions = EvaluateExDate(referenceDate, periodStart, periodEnd);

            //Exclusions trump inclusions
            Periods.UnionWith(rruleOccurrences);
            Periods.UnionWith(rdateOccurrences);
            Periods.ExceptWith(exRuleExclusions);
            Periods.ExceptWith(exDateExclusions);

            var dateOverlaps = FindDateOverlaps(exDateExclusions);

            Periods.ExceptWith(dateOverlaps);

            if (EvaluationStartBounds == DateTime.MaxValue || EvaluationStartBounds > periodStart)
            {
                EvaluationStartBounds = periodStart;
            }
            if (EvaluationEndBounds == DateTime.MinValue || EvaluationEndBounds < periodEnd)
            {
                EvaluationEndBounds = periodEnd;
            }

            return(Periods);
        }