Exemplo n.º 1
0
 /// <summary>
 /// Simple version: Find the next iteration of a task based upon its TimeInfo.
 /// </summary>
 /// <param name="Rules">TimeInfo to base checking rules upon.</param>
 /// <returns>DateTime of next iteration.</returns>
 public static DateTime FindNextIteration(TimeInfo Rules)
 {
     return(FindNextIteration(DateTime.Now, Rules));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Detailed version: Find the next iteration of a task starting from BaseTime based upon its TimeInfo.
        /// </summary>
        /// <param name="BaseTime">Starting date from which to begin iteration search.</param>
        /// <param name="Rules">TimeInfo to base checking rules upon.</param>
        /// <returns>DateTime of next iteration.</returns>
        public static DateTime FindNextIteration(DateTime BaseTime, TimeInfo Rules)
        {
            DateTime NextTime = new DateTime();

            NextTime = BaseTime;

            // set hours/minutes/seconds
            NextTime = NextTime - NextTime.TimeOfDay;
            NextTime = NextTime + Rules.TimeOfDay;

            // SIMPLE RECURRANCE
            // Increment from "start date"
            if ((Rules.Yearly + Rules.Monthly + Rules.Weekly + Rules.Daily) > 0)
            {
                NextTime = Rules.Start;

                for (int hops = 1; hops <= 3650; ++hops)
                {
                    //Rules.Count = hops;
                    if (NextTime > BaseTime)
                    {
                        return(NextTime);
                    }

                    NextTime = NextTime.AddYears(Rules.Yearly);
                    NextTime = NextTime.AddMonths(Rules.Monthly);
                    NextTime = NextTime.AddDays(Rules.Weekly * 7);
                    NextTime = NextTime.AddDays(Rules.Daily);
                }
            }

            // COMPLEX RECURRANCE: Filter month/week/day by flags
            // Increment NextTime until we find a day that matches all of our criteria
            else if ((Rules.MonthFilter != 0) || (Rules.WeekFilter != 0) || (Rules.DayFilter != 0))
            {
                for (int hops = 1; hops <= 3650; ++hops)                 // maximum search of 10 years
                {
                    if ((Rules.MonthFilter & FromMonthToFlag(NextTime.Month)) != 0)
                    {
                        // if we're searching for the last week, automatically jump to the last 7 days of the month
                        bool FindingLastWeek = false;
                        if ((Rules.WeekFilter & WeekFlag.Last) != 0)
                        {
                            if (NextTime.Day >= (DateTime.DaysInMonth(NextTime.Year, NextTime.Month) - 7))
                            {
                                FindingLastWeek = true;
                            }
                        }

                        if (((Rules.WeekFilter & FromWeekToFlag(NextTime.Day)) != 0) || FindingLastWeek)
                        {
                            if ((Rules.DayFilter & FromDayToFlag(NextTime.DayOfWeek)) != 0)
                            {
                                if (NextTime > BaseTime)
                                {
                                    if (Rules.SpecificDay != 0)
                                    {
                                        if (NextTime.Day == Rules.SpecificDay)
                                        {
                                            return(NextTime);
                                        }
                                    }
                                    else
                                    {
                                        return(NextTime);
                                    }
                                }
                            }
                        }
                    }

                    NextTime = NextTime.AddDays(1);
                }
            }

            // NON-RECURRANCE: Item has no rules that allow it to recur
            return(DateTime.MinValue);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Simple version: Find the iteration count of a task based upon its TimeInfo.
 /// </summary>
 /// <param name="Rules">TimeInfo to base checking rules upon.</param>
 /// <returns>Integer for the number of iterations found.</returns>
 public static int FindIterationCount(TimeInfo Rules)
 {
     return(FindIterationCount(Rules.Start, DateTime.Now, Rules));
 }