Пример #1
0
        /// <summary>
        /// Determine the next time (in milliseconds) that is 'included' by the
        /// Calendar after the given time. Return the original value if timeStamp is
        /// included. Return 0 if all days are excluded.
        /// </summary>
        /// <param name="timeUtc"></param>
        /// <returns></returns>
        /// <seealso cref="ICalendar.GetNextIncludedTimeUtc"/>
        public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc)
        {
            DateTimeOffset nextIncludedTime = timeUtc.AddMilliseconds(OneMillis);

            while (!IsTimeIncluded(nextIncludedTime))
            {
                if (!InvertTimeRange)
                {
                    //If the time is in a range excluded by this calendar, we can
                    // move to the end of the excluded time range and continue
                    // testing from there. Otherwise, if nextIncludedTime is
                    // excluded by the baseCalendar, ask it the next time it
                    // includes and begin testing from there. Failing this, add one
                    // millisecond and continue testing.
                    if (nextIncludedTime >=
                        GetTimeRangeStartingTimeUtc(nextIncludedTime) &&
                        nextIncludedTime <=
                        GetTimeRangeEndingTimeUtc(nextIncludedTime))
                    {
                        nextIncludedTime =
                            GetTimeRangeEndingTimeUtc(nextIncludedTime).AddMilliseconds(OneMillis);
                    }
                    else if (CalendarBase != null &&
                             !CalendarBase.IsTimeIncluded(nextIncludedTime))
                    {
                        nextIncludedTime =
                            CalendarBase.GetNextIncludedTimeUtc(nextIncludedTime);
                    }
                    else
                    {
                        nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                    }
                }
                else
                {
                    //If the time is in a range excluded by this calendar, we can
                    // move to the end of the excluded time range and continue
                    // testing from there. Otherwise, if nextIncludedTime is
                    // excluded by the baseCalendar, ask it the next time it
                    // includes and begin testing from there. Failing this, add one
                    // millisecond and continue testing.
                    if (nextIncludedTime <
                        GetTimeRangeStartingTimeUtc(nextIncludedTime))
                    {
                        nextIncludedTime =
                            GetTimeRangeStartingTimeUtc(nextIncludedTime);
                    }
                    else if (nextIncludedTime >
                             GetTimeRangeEndingTimeUtc(nextIncludedTime))
                    {
                        //(move to start of next day)
                        nextIncludedTime = GetEndOfDay(nextIncludedTime);
                        nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                    }
                    else if (CalendarBase != null &&
                             !CalendarBase.IsTimeIncluded(nextIncludedTime))
                    {
                        nextIncludedTime =
                            CalendarBase.GetNextIncludedTimeUtc(nextIncludedTime);
                    }
                    else
                    {
                        nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                    }
                }
            }

            return(nextIncludedTime);
        }