예제 #1
0
        public void SkippedOccurrenceOnWeeklyPattern()
        {
            const int evaluationsCount = 1000;
            var       eventStart       = new CalDateTime(new DateTime(2016, 1, 1, 10, 0, 0, DateTimeKind.Utc));
            var       eventEnd         = new CalDateTime(new DateTime(2016, 1, 1, 11, 0, 0, DateTimeKind.Utc));
            var       vEvent           = new CalendarEvent
            {
                DtStart = eventStart,
                DtEnd   = eventEnd,
            };

            var pattern = new RecurrencePattern
            {
                Frequency = FrequencyType.Weekly,
                ByDay     = new List <WeekDay> {
                    new WeekDay(DayOfWeek.Friday)
                }
            };

            vEvent.RecurrenceRules.Add(pattern);
            var calendar = new Calendar();

            calendar.Events.Add(vEvent);

            var intervalStart = eventStart;
            var intervalEnd   = intervalStart.AddDays(7 * evaluationsCount);

            var occurrences = RecurrenceUtil.GetOccurrences(
                recurrable: vEvent,
                periodStart: intervalStart,
                periodEnd: intervalEnd,
                includeReferenceDateInResults: false);
            var occurrenceSet = new HashSet <IDateTime>(occurrences.Select(o => o.Period.StartTime));

            Assert.AreEqual(evaluationsCount, occurrenceSet.Count);

            for (var currentOccurrence = intervalStart; currentOccurrence.CompareTo(intervalEnd) < 0; currentOccurrence = (CalDateTime)currentOccurrence.AddDays(7))
            {
                var contains = occurrenceSet.Contains(currentOccurrence);
                Assert.IsTrue(contains, $"Collection does not contain {currentOccurrence}, but it is a {currentOccurrence.DayOfWeek}");
            }
        }
예제 #2
0
        public void SkippedOccurrenceOnWeeklyPattern()
        {
            const int evaluationsCount = 1000;
            var       eventStart       = new CalDateTime(new DateTime(2016, 1, 1, 10, 0, 0, DateTimeKind.Utc));
            var       eventEnd         = new CalDateTime(new DateTime(2016, 1, 1, 11, 0, 0, DateTimeKind.Utc));
            var       vEvent           = new CalendarEvent
            {
                DtStart = eventStart,
                DtEnd   = eventEnd,
            };

            var pattern = new RecurrencePattern
            {
                Frequency = FrequencyType.Weekly,
                ByDay     = new List <WeekDay> {
                    new WeekDay(DayOfWeek.Friday)
                }
            };

            vEvent.RecurrenceRules.Add(pattern);
            var calendar = new Calendar();

            calendar.Events.Add(vEvent);

            var intervalStart = eventStart;
            var intervalEnd   = intervalStart.AddDays(7 * evaluationsCount);

            var occurrences = RecurrenceUtil.GetOccurrences(vEvent, intervalStart, intervalEnd, false)
                              .Select(o => o.Period.StartTime)
                              .OrderBy(dt => dt)
                              .ToList();

            Assert.AreEqual(evaluationsCount, occurrences.Count);

            for (var currentOccurrence = intervalStart.AsUtc; currentOccurrence.CompareTo(intervalEnd.AsUtc) < 0; currentOccurrence = currentOccurrence.AddDays(7))
            {
                Assert.IsTrue(occurrences.Contains(new CalDateTime(currentOccurrence)),
                              $"Collection does not contain {currentOccurrence}, but it is a {currentOccurrence.DayOfWeek}");
            }
        }
예제 #3
0
 public virtual HashSet <Occurrence> GetOccurrences(IDateTime startTime, IDateTime endTime)
 {
     return(RecurrenceUtil.GetOccurrences(this, startTime, endTime, EvaluationIncludesReferenceDate));
 }
예제 #4
0
 public virtual HashSet <Occurrence> GetOccurrences(DateTime startTime, DateTime endTime)
 {
     return(RecurrenceUtil.GetOccurrences(this, new CalDateTime(startTime), new CalDateTime(endTime), EvaluationIncludesReferenceDate));
 }
예제 #5
0
 public virtual HashSet <Occurrence> GetOccurrences(DateTime dt)
 {
     return(RecurrenceUtil.GetOccurrences(this, new CalDateTime(dt), EvaluationIncludesReferenceDate));
 }
예제 #6
0
 public virtual HashSet <Occurrence> GetOccurrences(DateTime startTime, DateTime endTime)
 {
     return(RecurrenceUtil.GetOccurrences(this, new CalDateTime(startTime), new CalDateTime(endTime), true));
 }
예제 #7
0
 public virtual HashSet <Occurrence> GetOccurrences(IDateTime startTime, IDateTime endTime)
 {
     return(RecurrenceUtil.GetOccurrences(this, startTime, endTime, true));
 }
예제 #8
0
 public virtual HashSet <Occurrence> GetOccurrences(DateTime dt)
 {
     return(RecurrenceUtil.GetOccurrences(this, new CalDateTime(dt), true));
 }
예제 #9
0
 public virtual HashSet <Occurrence> GetOccurrences(IDateTime dt)
 {
     return(RecurrenceUtil.GetOccurrences(this, dt, true));
 }