예제 #1
0
        protected override IEnumerable <Occurrence> GetNextOccurrences(Occurrence lastOccurrence, TimeSpan startTime, TimeSpan endTime)
        {
            int[]    days;
            DateTime startDate;

            if (lastOccurrence != null)
            {
                startDate = lastOccurrence.Start.Date.Add(startTime).AddDays(1 - lastOccurrence.Start.Day).AddMonths(Interval);
                days      = SPRecurrenceHelper.GetMatchedDays(startDate, DayOfWeekOrdinal, DayOfWeek).ToArray();
            }
            else
            {
                startDate = StartDate.Date.Add(startTime);
                if (StartDate > startDate)
                {
                    startDate = StartDate;
                }
                days = SPRecurrenceHelper.GetMatchedDays(startDate, DayOfWeekOrdinal, DayOfWeek).ToArray();
                if (days.Length == 0)
                {
                    startDate = startDate.AddDays(1 - startDate.Day).AddMonths(1);
                    days      = SPRecurrenceHelper.GetMatchedDays(startDate, DayOfWeekOrdinal, DayOfWeek).ToArray();
                }
            }
            foreach (int day in days)
            {
                startDate = startDate.AddDays(day - startDate.Day);
                DateTime endDate = startDate.Date.Add(endTime);
                if (startDate <= endDate)
                {
                    if (EndDate.HasValue && endDate >= EndDate.Value)
                    {
                        yield return(new Occurrence(startDate, EndDate.Value));
                    }
                    else
                    {
                        yield return(new Occurrence(startDate, endDate));
                    }
                }
            }
        }
예제 #2
0
        protected override IEnumerable <Occurrence> GetNextOccurrences(Occurrence lastOccurrence, TimeSpan startTime, TimeSpan endTime)
        {
            DateTime startDate;

            if (lastOccurrence != null)
            {
                startDate = lastOccurrence.Start.Date.Add(startTime).AddDays(7 * Interval);
            }
            else
            {
                startDate = StartDate.Date.Add(startTime);
                if (StartDate > startDate)
                {
                    startDate = StartDate;
                }
            }
            while (startDate.DayOfWeek != FirstDayOfWeek)
            {
                startDate = startDate.AddDays(-1);
            }
            do
            {
                DateTime endDate = startDate.Date.Add(endTime);
                if (startDate <= endDate)
                {
                    if (SPRecurrenceHelper.IsDayOfWeekMatched(DaysOfWeek, startDate))
                    {
                        if (EndDate.HasValue && endDate >= EndDate.Value)
                        {
                            yield return(new Occurrence(startDate, EndDate.Value));
                        }
                        else
                        {
                            yield return(new Occurrence(startDate, endDate));
                        }
                    }
                }
                startDate = startDate.AddDays(1);
            } while (startDate.DayOfWeek != FirstDayOfWeek);
        }