//********************************************************************* // TEMPORAL "RECURRENCE" FUNCTIONS //********************************************************************* /// <summary> /// Loops (cycles) through numbers over time (e.g. 1 2 3 4 1 2 3 4 ...) /// </summary> public static Tnum Recurrence(Tdate startDate, Tdate endDate, IntervalType interval, int min, int max) { // Handle unknowns Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue); if (top != Hstate.Known) { return(new Tnum(new Hval(null, top))); } DateTime start = startDate.ToDateTime; DateTime end = endDate.ToDateTime; Tnum result = new Tnum(); if (start != Time.DawnOf) { result.AddState(Time.DawnOf, 0); } DateTime indexDate = start; int indexNumber = min; while (indexDate < end) { result.AddState(indexDate, Convert.ToString(indexNumber)); indexDate = indexDate.AddInterval(interval, 1); // Reset sequence indexNumber++; if (indexNumber > max) { indexNumber = min; } } result.AddState(end, 0); return(result); }
public static Tnum IntervalsSince(Tdate startDate, Tdate endDate, IntervalType interval, int?startAt) { // Handle unknowns Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue); if (top != Hstate.Known) { return(new Tnum(new Hval(null, top))); } DateTime start = startDate.ToDateTime; DateTime end = endDate.ToDateTime; Tnum result = new Tnum(); if (start != Time.DawnOf) { result.AddState(Time.DawnOf, 0); } DateTime indexDate = start; int? indexNumber = startAt; while (indexDate < end) { result.AddState(indexDate, Convert.ToDecimal(indexNumber)); indexNumber++; indexDate = indexDate.AddInterval(interval, 1); } if (end < Time.EndOf) { result.AddState(end, 0); } return(result); }