Beispiel #1
0
        protected void IncrementDate(ref DateTime dt, RecurrencePattern pattern, int interval)
        {
            // FIXME: use a more specific exception.
            if (interval == 0)
            {
                throw new Exception("Cannot evaluate with an interval of zero.  Please use an interval other than zero.");
            }

            var old = dt;

            switch (pattern.Frequency)
            {
            case FrequencyType.Secondly:
                dt = old.AddSeconds(interval);
                break;

            case FrequencyType.Minutely:
                dt = old.AddMinutes(interval);
                break;

            case FrequencyType.Hourly:
                dt = old.AddHours(interval);
                break;

            case FrequencyType.Daily:
                dt = old.AddDays(interval);
                break;

            case FrequencyType.Weekly:
                dt = DateUtil.AddWeeks(old, interval, pattern.FirstDayOfWeek);
                break;

            case FrequencyType.Monthly:
                dt = old.AddDays(-old.Day + 1).AddMonths(interval);
                break;

            case FrequencyType.Yearly:
                dt = old.AddDays(-old.DayOfYear + 1).AddYears(interval);
                break;

            // FIXME: use a more specific exception.
            default:
                throw new Exception("FrequencyType.NONE cannot be evaluated. Please specify a FrequencyType before evaluating the recurrence.");
            }
        }