/// <summary> /// This is used to filter 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> public static int ByMonth(Recurrence r, RecurDateTimeCollection dates) { int count = dates.Count; // Don't bother if either collection is empty if (count != 0 && r.ByMonth.Count != 0) { for (int idx = 0, collIdx = 0; idx < count; idx++) { // Remove the date/time if the month isn't wanted if (!r.isMonthUsed[dates[collIdx].Month]) { dates.RemoveAt(collIdx); count--; idx--; } else { collIdx++; } } } return(dates.Count); }
/// <summary> /// This is used to filter the secondly frequency 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> public int BySecond(Recurrence r, RecurDateTimeCollection dates) { int count = dates.Count; // Don't bother if either collection is empty if (count != 0 && r.BySecond.Count != 0) { for (int idx = 0, nCollIdx = 0; idx < count; idx++) { // Remove the date/time if the second isn't wanted if (!r.isSecondUsed[dates[nCollIdx].Second]) { dates.RemoveAt(nCollIdx); count--; idx--; } else { nCollIdx++; } } } return(dates.Count); }
/// <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> /// 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); }
/// <summary> /// This is used to filter 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 a date in the collection is invalid, it will be discarded</remarks> public static int ByYearDay(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt; int days, count = dates.Count; // Don't bother if either collection is empty if (count != 0 && r.ByYearDay.Count != 0) { for (int idx = 0, collIdx = 0; idx < count; idx++) { rdt = dates[collIdx]; // If not valid, discard it if (!rdt.IsValidDate()) { dates.RemoveAt(collIdx); count--; idx--; continue; } days = (DateTime.IsLeapYear(rdt.Year)) ? 367 : 366; // Remove the date/time if the year day isn't wanted. Check both from the start of the year // and from the end of the year. if (!r.isYearDayUsed[rdt.DayOfYear] && !r.isNegYearDayUsed[days - rdt.DayOfYear]) { dates.RemoveAt(collIdx); count--; idx--; } else { collIdx++; } } } return(dates.Count); }
/// <summary> /// This is used to filter by month 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 a date in the collection is invalid, it will be discarded</remarks> public static int ByMonthDay(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt; int count = dates.Count; // Don't bother if either collection is empty if (count != 0 && r.ByMonthDay.Count != 0) { for (int idx = 0, collIdx = 0; idx < count; idx++) { rdt = dates[collIdx]; // If not valid, discard it if (!rdt.IsValidDate()) { dates.RemoveAt(collIdx); count--; idx--; continue; } // Remove the date/time if the month day isn't wanted. Check both from the start of the // month and from the end of the month. if (!r.isMonthDayUsed[rdt.Day] && !r.isNegMonthDayUsed[DateTime.DaysInMonth(rdt.Year, rdt.Month + 1) - rdt.Day + 1]) { dates.RemoveAt(collIdx); count--; idx--; } else { collIdx++; } } } return(dates.Count); }
/// <summary> /// This is used to filter by day of the week /// </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 ByDay(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt; int count = dates.Count; // Don't bother if either collection is empty if (count != 0 && r.ByDay.Count != 0) { for (int idx = 0, collIdx = 0; idx < count; idx++) { rdt = dates[collIdx]; // If not valid, discard it if (!rdt.IsValidDate()) { dates.RemoveAt(collIdx); count--; idx--; continue; } // Remove the date/time if the weekday isn't wanted if (!r.isDayUsed[(int)rdt.DayOfWeek]) { dates.RemoveAt(collIdx); count--; idx--; } else { collIdx++; } } } return(dates.Count); }
/// <summary> /// This is used to expand one or more weeks by day of the week /// </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 static int ByDayInWeeks(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; int expIdx, count = dates.Count; DayInstanceCollection byDay = r.ByDay; // Don't bother if either collection is empty if (count != 0 && byDay.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 day of the week. As with filtering, // the instance number is ignored as it isn't useful here. For this, the "week" is the seven // day period starting on the occurrence date. for (expIdx = 0; expIdx < byDay.Count; expIdx++) { rdtNew = new RecurDateTime(rdt); rdtNew.AddDays((((int)byDay[expIdx].DayOfWeek + 7 - (int)r.WeekStart) % 7) - (((int)rdt.DayOfWeek + 7 - (int)r.WeekStart) % 7)); dates.Add(rdtNew); } } } return(dates.Count); }
/// <summary> /// This is used to filter the minutely 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> public int ByMonth(Recurrence r, RecurDateTimeCollection dates) { return(Filter.ByMonth(r, dates)); }
/// <summary> /// This is used to expand the minutely frequency 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> public int BySecond(Recurrence r, RecurDateTimeCollection dates) { return(Expand.BySecond(r, dates)); }
/// <summary> /// ByWeekNo is only applicable in the Yearly frequency and is ignored for the Minutely frequency /// </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> public int ByWeekNo(Recurrence r, RecurDateTimeCollection dates) { return(dates.Count); }
/// <summary> /// This is used to expand the yearly frequency by day of the week /// </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 ByDay(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; DayOfWeek dow; int expIdx, instance, count = dates.Count; DayInstanceCollection byDay = r.ByDay; // Don't bother if either collection is empty if (count != 0 && byDay.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 week day instance specified for (expIdx = 0; expIdx < byDay.Count; expIdx++) { instance = byDay[expIdx].Instance; dow = byDay[expIdx].DayOfWeek; if (instance == 0) { // Expand to every specified day of the week in the year rdtNew = new RecurDateTime(rdt); rdtNew.Month = 0; rdtNew.Day = 1; rdtNew.AddDays(((int)dow + 7 - (int)rdtNew.DayOfWeek) % 7); while (rdtNew.Year == rdt.Year) { dates.Add(new RecurDateTime(rdtNew)); rdtNew.AddDays(7); } continue; } if (instance > 0) { // Add the nth instance of the day of the week rdtNew = new RecurDateTime(rdt); rdtNew.Month = 0; rdtNew.Day = 1; rdtNew.AddDays((((int)dow + 7 - (int)rdtNew.DayOfWeek) % 7) + ((instance - 1) * 7)); } else { // Add the nth instance of the day of the week from the end of the year rdtNew = new RecurDateTime(rdt); rdtNew.Month = 11; rdtNew.Day = 31; rdtNew.AddDays(0 - (((int)rdtNew.DayOfWeek + 7 - (int)dow) % 7) + ((instance + 1) * 7)); } // If not in the year, discard it if (rdtNew.Year != rdt.Year) { continue; } dates.Add(new RecurDateTime(rdtNew)); } } } return(dates.Count); }
/// <summary> /// This is used to expand the yearly frequency by month 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> public int ByMonthDay(Recurrence r, RecurDateTimeCollection dates) { return(Expand.ByMonthDay(r, dates)); }
/// <summary> /// This is used to expand the weekly frequency by day of the week /// </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 ByDay(Recurrence r, RecurDateTimeCollection dates) { return(Expand.ByDayInWeeks(r, dates)); }