Ejemplo n.º 1
0
 public bool ShowDescriptionOnDate(DateTime date)
 {
     return(ActiveWeekDays.Contains(date.DayOfWeek));
 }
        internal bool GetNextRecurDate(DateTime originDate, out DateTime nextDate)
        {
            if (!this.Recuring)
            {
                throw new InvalidOperationException();
            }

            if (this.ReccurPeriod == null)
            {
                throw new InvalidOperationException();
            }

            switch (ReccurPeriod.TimeUnit)
            {
            case ReccurPeriodTimeUnit.Daily:
                nextDate = originDate.Date.AddDays(ReccurPeriod.TimeUnitCount);
                return(!HasEndDate || nextDate <= EndDate);

            case ReccurPeriodTimeUnit.Weekly:
                nextDate = new DateTime();

                if (ActiveWeekDays.Count == 0)
                {
                    return(false);
                }

                // this week
                var day = originDate.Date;

                while (day.Date.AddDays(1).DayOfWeek > day.DayOfWeek)
                {
                    day = day.AddDays(1);

                    if (ActiveWeekDays.Contains(day.DayOfWeek))
                    {
                        nextDate = day;
                        return(!HasEndDate || nextDate <= EndDate);
                    }
                }

                const int daysInWeek = 7;
                //First day of next active week
                day = day.AddDays(1 + daysInWeek * (ReccurPeriod.TimeUnitCount - 1));

                do
                {
                    if (ActiveWeekDays.Contains(day.DayOfWeek))
                    {
                        nextDate = day;
                        return(!HasEndDate || nextDate <= EndDate);
                    }

                    day = day.AddDays(1);
                } while (day.DayOfWeek > day.AddDays(-1).DayOfWeek);

                Debug.Fail("");
                return(false);

            case ReccurPeriodTimeUnit.Monthly:
                nextDate = DayOfMonth.GetDateOfThisMonth(originDate);

                if (nextDate <= originDate)
                {
                    var nextMonth = DayOfMonthSettings.BeginingOfMonth(nextDate)
                                    .AddMonths(ReccurPeriod.TimeUnitCount);

                    nextDate = DayOfMonth.GetDateOfThisMonth(nextMonth);
                }
                return(!HasEndDate || nextDate <= EndDate);

            default:
                throw new Exception("Unforseen enum value");
            }
        }