/// <summary> /// This is used to find the starting point for the secondly 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) { RecurDateTime rdt = new RecurDateTime(start); int adjust; if (RecurDateTime.Compare(start, from, RecurDateTime.DateTimePart.Hour) < 0) { // Get the difference between the recurrence start and the limiting range start DateTime dtStart = start.ToDateTime(), dtFrom = from.ToDateTime(); // Adjust the date/time so that it's in range TimeSpan ts = dtFrom - dtStart; adjust = (int)ts.TotalSeconds + r.Interval - 1; rdt.AddSeconds(adjust - (adjust % r.Interval)); } if (RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Hour) > 0 || RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Hour) > 0) { return(null); } return(rdt); }
/// <summary> /// This is used to find the starting point for the daily 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) { RecurDateTime rdt = new RecurDateTime(start); int adjust; // Get the difference between the recurrence start and the limiting range start DateTime dtStart = start.ToDateTime().Date, dtFrom = from.ToDateTime().Date; // Adjust the date so that it's in range if (dtStart < dtFrom) { TimeSpan ts = dtFrom - dtStart; adjust = ts.Days + r.Interval - 1; rdt.AddDays(adjust - (adjust % r.Interval)); } if (RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Day) > 0 || RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Day) > 0) { return(null); } return(rdt); }
/// <summary> /// This is used to find the starting point for the weekly 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) { RecurDateTime rdtWeek, rdt = new RecurDateTime(start); int adjust; // Get the difference between the recurrence start and the limiting range start DateTime dtStart = start.ToDateTime().Date.AddDays(0 - r.weekdayOffset); DateTime dtFrom = from.ToDateTime().Date; dtFrom = dtFrom.AddDays(0 - ((int)dtFrom.DayOfWeek + 7 - (int)r.WeekStart) % 7); // Adjust the date so that it's in range if (dtStart < dtFrom) { TimeSpan ts = dtFrom - dtStart; adjust = (ts.Days / 7) + r.Interval - 1; rdt.AddDays((adjust - (adjust % r.Interval)) * 7); } // If the start of the week is after the ranges, stop now rdtWeek = new RecurDateTime(rdt); rdtWeek.AddDays(0 - r.weekdayOffset); if (RecurDateTime.Compare(rdtWeek, end, RecurDateTime.DateTimePart.Day) > 0 || RecurDateTime.Compare(rdtWeek, to, RecurDateTime.DateTimePart.Day) > 0) { return(null); } return(rdt); }
//===================================================================== /// <summary> /// Compares this instance to a specified object and returns an indication of their relative values /// </summary> /// <param name="obj">An object to compare or null</param> /// <returns>Returns -1 if this instance is less than the value, 0 if they are equal, or 1 if this /// instance is greater than the value or the value is null.</returns> /// <exception cref="ArgumentException">This is thrown if the object to be compared is not a /// <c>RecurDateTime</c>.</exception> public int CompareTo(object obj) { RecurDateTime rd = obj as RecurDateTime; if (rd == null) { throw new ArgumentException(LR.GetString("ExRDTBadCompareObject")); } return(RecurDateTime.Compare(this, rd)); }
/// <summary> /// This is used to find the next instance of the daily 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.AddDays(r.Interval); if (RecurDateTime.Compare(last, end, RecurDateTime.DateTimePart.Day) > 0 || RecurDateTime.Compare(last, to, RecurDateTime.DateTimePart.Day) > 0) { return(false); } return(true); }
/// <summary> /// This is used to find the next instance of the weekly 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) { RecurDateTime rdtWeek; last.AddDays(r.Interval * 7); // For this one, compare the week start date rdtWeek = new RecurDateTime(last); rdtWeek.AddDays(0 - r.weekdayOffset); if (RecurDateTime.Compare(rdtWeek, end, RecurDateTime.DateTimePart.Day) > 0 || RecurDateTime.Compare(rdtWeek, to, RecurDateTime.DateTimePart.Day) > 0) { return(false); } return(true); }
/// <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); }
/// <summary> /// Overload for greater than or equal operator /// </summary> /// <param name="r1">The first date/time object</param> /// <param name="r2">The second date/time object</param> /// <returns>True if r1 is greater than or equal to r2, false if not</returns> public static bool operator >=(RecurDateTime r1, RecurDateTime r2) { return(RecurDateTime.Compare(r1, r2) >= 0); }