Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's the function that yields the intersection of the Recurrence points and a specified subinterval:</p> <pre><code>public class Recurrence { public int Id { get; protected set; } public DateTime StartDate { get; protected set; } public DateTime? EndDate { get; protected set; } public long? RecurrenceInterval { get; protected set; } // returns the set of DateTimes within [subStart, subEnd] that are // of the form StartDate + k*RecurrenceInterval, where k is an Integer public IEnumerable&lt;DateTime&gt; GetBetween(DateTime subStart, DateTime subEnd) { long stride = RecurrenceInterval ?? 1; if (stride &lt; 1) throw new ArgumentException("Need a positive recurrence stride"); long realStart, realEnd; // figure out where we really need to start if (StartDate &gt;= subStart) realStart = StartDate.Ticks; else { long rem = subStart.Ticks % stride; if (rem == 0) realStart = subStart.Ticks; else // break off the incomplete stride and add a full one realStart = subStart.Ticks - rem + stride; } // figure out where we really need to stop if (EndDate &lt;= subEnd) // we know EndDate has a value. Null can't be "less than" something realEnd = EndDate.Value.Ticks; else { long rem = subEnd.Ticks % stride; // break off any incomplete stride realEnd = subEnd.Ticks - rem; } if (realEnd &lt; realStart) yield break; // the intersection is empty // now yield all the results in the intersection of the sets for (long t = realStart; t &lt;= realEnd; t += stride) yield return new DateTime(t); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload