/// <summary> /// This is used to expand the yearly frequency by month /// </summary> /// <param name="r">A reference to the recurrence</param> /// <param name="dates">A reference to the collection of current instances that have been generated</param> /// <returns>The number of instances in the collection. If zero, subsequent rules don't have to be /// checked as there's nothing else to do.</returns> /// <remarks>This may generate invalid dates (i.e. June 31st). These will be removed later.</remarks> public int ByMonth(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; int expIdx, count = dates.Count; UniqueIntegerCollection byMonth = r.ByMonth; // Don't bother if either collection is empty if (count != 0 && byMonth.Count != 0) { for (int idx = 0; idx < count; idx++) { rdt = dates[0]; dates.RemoveAt(0); // Expand the date/time by adding a new entry for each month specified for (expIdx = 0; expIdx < byMonth.Count; expIdx++) { rdtNew = new RecurDateTime(rdt); rdtNew.Month = byMonth[expIdx] - 1; dates.Add(rdtNew); } } } return(dates.Count); }
/// <summary> /// This is used to expand by second /// </summary> /// <param name="r">A reference to the recurrence</param> /// <param name="dates">A reference to the collection of current instances that have been generated</param> /// <returns>The number of instances in the collection. If zero, subsequent rules don't have to be /// checked as there's nothing else to do.</returns> /// <remarks>If a date in the collection is invalid, it will be discarded</remarks> public static int BySecond(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; int expIdx, count = dates.Count; UniqueIntegerCollection bySecond = r.BySecond; // Don't bother if either collection is empty if (count != 0 && bySecond.Count != 0) { for (int idx = 0; idx < count; idx++) { rdt = dates[0]; dates.RemoveAt(0); // If not valid, discard it if (!rdt.IsValidDate()) { continue; } // Expand the date/time by adding a new entry for each second specified for (expIdx = 0; expIdx < bySecond.Count; expIdx++) { rdtNew = new RecurDateTime(rdt); rdtNew.Second = bySecond[expIdx]; dates.Add(rdtNew); } } } return(dates.Count); }
/// <summary> /// Copy constructor /// </summary> /// <param name="values">The <c>UniqueIntegerCollection</c> to copy. The range and zero exclusion /// setting are inherited from the copied collection.</param> public UniqueIntegerCollection(UniqueIntegerCollection values) { if (values != null) { minValue = values.MinimumValue; maxValue = values.MaximumValue; allowZero = values.AllowZero; this.AddRange(values); } }
/// <summary> /// This is used to expand the yearly frequency by week number /// </summary> /// <param name="r">A reference to the recurrence</param> /// <param name="dates">A reference to the collection of current instances that have been generated</param> /// <returns>The number of instances in the collection. If zero, subsequent rules don't have to be /// checked as there's nothing else to do.</returns> /// <remarks>If an expanded date is invalid, it will be discarded</remarks> public int ByWeekNo(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; int expIdx, week, yearWeeks, count = dates.Count; UniqueIntegerCollection byWeekNo = r.ByWeekNo; // Don't bother if either collection is empty if (count != 0 && byWeekNo.Count != 0) { for (int idx = 0; idx < count; idx++) { rdt = dates[0]; yearWeeks = DateUtils.WeeksInYear(rdt.Year, r.WeekStart); dates.RemoveAt(0); // Expand the date/time by adding a new entry for each week number specified for (expIdx = 0; expIdx < byWeekNo.Count; expIdx++) { week = byWeekNo[expIdx]; // If not in the year, discard it if ((week == 53 || week == -53) && yearWeeks == 52) { continue; } if (week > 0) { rdtNew = new RecurDateTime(DateUtils.DateFromWeek(rdt.Year, week, r.WeekStart, r.weekdayOffset)); } else { rdtNew = new RecurDateTime(DateUtils.DateFromWeek(rdt.Year, yearWeeks + week + 1, r.WeekStart, r.weekdayOffset)); } rdtNew.Hour = rdt.Hour; rdtNew.Minute = rdt.Minute; rdtNew.Second = rdt.Second; dates.Add(rdtNew); } } } return(dates.Count); }
/// <summary> /// This is used to expand the yearly frequency by year day /// </summary> /// <param name="r">A reference to the recurrence</param> /// <param name="dates">A reference to the collection of current instances that have been generated</param> /// <returns>The number of instances in the collection. If zero, subsequent rules don't have to be /// checked as there's nothing else to do.</returns> /// <remarks>If an expanded date is invalid, it will be discarded</remarks> public int ByYearDay(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; int expIdx, yearDay, count = dates.Count; UniqueIntegerCollection byYearDay = r.ByYearDay; // Don't bother if either collection is empty if (count != 0 && byYearDay.Count != 0) { for (int idx = 0; idx < count; idx++) { rdt = dates[0]; dates.RemoveAt(0); // Expand the date/time by adding a new entry for each year day specified for (expIdx = 0; expIdx < byYearDay.Count; expIdx++) { yearDay = byYearDay[expIdx]; rdtNew = new RecurDateTime(rdt); rdtNew.Month = 0; rdtNew.Day = 1; // From start of year or end of year? if (yearDay > 0) { rdtNew.AddDays(yearDay - 1); } else { rdtNew.Year++; rdtNew.AddDays(yearDay); } // If not in the year, discard it if (rdtNew.Year != rdt.Year) { continue; } dates.Add(rdtNew); } } } return(dates.Count); }