/// <summary> /// This is used to handle the expansion of the yearly frequency /// </summary> /// <param name="dates">The collection in which to put the dates</param> /// <remarks>The spec is rather vague about how all the rules should interact so I'm making some best /// guesses here based on the examples in the spec itself although not all combinations are shown. /// </remarks> private void ExpandYearly(RecurDateTimeCollection dates) { RecurDateTimeCollection rdtcMonth = null, rdtcMoDay = null, rdtcWeek = null, rdtcYrDay = null, rdtcDay = null; bool isExpanded = false; // We'll expand each rule individually and combine the results before applying the time expansions. // The application of the BYMONTHDAY and BYDAY rules varies based on whatever other rule parts are // present as well. if(byMonth.Count != 0) { // Expand by month isExpanded = true; rdtcMonth = new RecurDateTimeCollection(dates); freqRules.ByMonth(this, rdtcMonth); // If BYMONTHDAY and BYDAY are both specified, we need to expand by month day and then filter by // day. If we expand by day alone, note that we do so only in the months specified in the // BYMONTH rule. if(byMonthDay.Count != 0 && byDay.Count != 0) { Expand.ByMonthDay(this, rdtcMonth); Filter.ByDay(this, rdtcMonth); } else if(Expand.ByMonthDay(this, rdtcMonth) != 0) Expand.ByDayInMonths(this, rdtcMonth); } else { if(byMonthDay.Count != 0) { // Expand by month day if specified without any by month rule part isExpanded = true; rdtcMoDay = new RecurDateTimeCollection(dates); freqRules.ByMonthDay(this, rdtcMoDay); } // As long as by week number isn't specified either, we'll expand the by day rule here too if(byWeekNo.Count == 0) { isExpanded = true; rdtcDay = new RecurDateTimeCollection(dates); freqRules.ByDay(this, rdtcDay); } } if(byWeekNo.Count != 0) { // Expand by week number isExpanded = true; rdtcWeek = new RecurDateTimeCollection(dates); freqRules.ByWeekNo(this, rdtcWeek); // Expand by days of the week in those weeks Expand.ByDayInWeeks(this, rdtcWeek); } if(byYearDay.Count != 0) { // Expand by year day isExpanded = true; rdtcYrDay = new RecurDateTimeCollection(dates); freqRules.ByYearDay(this, rdtcYrDay); } // Combine the various expansions. If nothing was done, leave the original date in the collection. if(isExpanded) { dates.Clear(); if(rdtcMonth != null && rdtcMonth.Count != 0) dates.AddRange(rdtcMonth); if(rdtcMoDay != null && rdtcMoDay.Count != 0) dates.AddRange(rdtcMoDay); if(rdtcWeek != null && rdtcWeek.Count != 0) dates.AddRange(rdtcWeek); if(rdtcYrDay != null && rdtcYrDay.Count != 0) dates.AddRange(rdtcYrDay); if(rdtcDay != null && rdtcDay.Count != 0) dates.AddRange(rdtcDay); } // In any case, the time parts are easy. They always expand the instances if there's anything there. if(dates.Count != 0) { Expand.ByHour(this, dates); Expand.ByMinute(this, dates); Expand.BySecond(this, dates); } }