/// <summary> /// This is used to find the next instance of the monthly frequency /// </summary> /// <param name="r">A reference to the recurrence</param> /// <param name="end">The recurrence end date</param> /// <param name="to">The end date of the range limiting the instances generated</param> /// <param name="last">This is used to pass in the last instance date calculated and return the next /// instance date</param> /// <returns>True if the recurrence has another instance or false if there are no more instances</returns> public bool FindNext(Recurrence r, RecurDateTime end, RecurDateTime to, RecurDateTime last) { last.AddMonths(r.Interval); if (RecurDateTime.Compare(last, end, RecurDateTime.DateTimePart.Month) > 0 || RecurDateTime.Compare(last, to, RecurDateTime.DateTimePart.Month) > 0) { return(false); } return(true); }
/// <summary> /// This is used to expand 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 an expanded date is invalid, it will be discarded</remarks> public static int ByMonthDay(Recurrence r, RecurDateTimeCollection dates) { RecurDateTime rdt, rdtNew; int expIdx, monthDay, count = dates.Count; UniqueIntegerCollection byMonthDay = r.ByMonthDay; // Don't bother if either collection is empty if (count != 0 && byMonthDay.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 day specified for (expIdx = 0; expIdx < byMonthDay.Count; expIdx++) { monthDay = byMonthDay[expIdx]; rdtNew = new RecurDateTime(rdt); rdtNew.Day = 1; // From start of month or end of month? if (monthDay > 0) { rdtNew.AddDays(monthDay - 1); } else { rdtNew.AddMonths(1); rdtNew.AddDays(monthDay); } // If not in the month, discard it if (rdtNew.Month != rdt.Month) { continue; } dates.Add(rdtNew); } } } return(dates.Count); }
/// <summary> /// This is used to find the starting point for the monthly frequency /// </summary> /// <param name="r">A reference to the recurrence</param> /// <param name="start">The recurrence start date</param> /// <param name="end">The recurrence end date</param> /// <param name="from">The start date of the range limiting the instances generated</param> /// <param name="to">The end date of the range limiting the instances generated</param> /// <returns>The first instance date or null if there are no more instances</returns> public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from, RecurDateTime to) { int adjust; RecurDateTime rdt = new RecurDateTime(start); // Adjust the date if the starting date is before the limiting range start date if (RecurDateTime.Compare(rdt, from, RecurDateTime.DateTimePart.Month) < 0) { adjust = ((from.Year - rdt.Year) * 12) + from.Month - rdt.Month + r.Interval - 1; rdt.AddMonths(adjust - (adjust % r.Interval)); } if (RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Month) > 0 || RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Month) > 0) { return(null); } return(rdt); }