Ejemplo n.º 1
0
 /// <summary>
 /// Create the first (or only) TimeSlice in a sequence.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <param name="inc"></param>
 /// <returns></returns>
 public static TimeSlice CreateInitial(DateTime from, DateTime to, double inc)
 {
     TimeSlice retval = null;
     bool incomplete = false;
     DateTime later;
     if (from > to)
     {
         later = from;
         if (inc > 0.0)
         {
             long intMillis = MillisecondsToTicks(inc);
             long totMillis = MillisecondsToTicks((from - to).TotalMilliseconds);
             long remMillis = totMillis % intMillis;
             later = (remMillis > 0) ? to + new TimeSpan(remMillis) : to + new TimeSpan(intMillis);
             incomplete = (remMillis > 0);
         }
         retval = new BackwardTimeSlice
         {
             From = later,
             To = to,
             Incomplete = incomplete,
             EarlyBound = new BoundingValue { Timestamp = to },
             LateBound = new BoundingValue { Timestamp = later }
         };
     }
     else if (to > from)
     {
         later = to;
         if (inc > 0.0)
         {
             later = from + new TimeSpan(MillisecondsToTicks(inc));
             if (later > to)
             {
                 later = to;
                 incomplete = true;
             }
         }
         retval = new ForwardTimeSlice
         {
             From = from,
             To = later,
             Incomplete = incomplete,
             EarlyBound = new BoundingValue { Timestamp = from },
             LateBound = new BoundingValue { Timestamp = later }
         };
     }
     //deliberately ignore (if from == to)
     return retval;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Create the TimeSlice that immediately follows this one in time.
 /// </summary>
 /// <param name="latest"></param>
 /// <param name="inc"></param>
 /// <returns></returns>
 protected override TimeSlice CreateSuccessor(DateTime latest, double inc)
 {
     TimeSlice retval = null;
     if (To < latest)
     {
         bool incomplete = false;
         DateTime target = To + new TimeSpan(MillisecondsToTicks(inc));
         if (target > latest)
         {
             target = latest;
             incomplete = true;
         }
         retval = new ForwardTimeSlice
         {
             From = this.To,
             To = target,
             Incomplete = incomplete,
             EarlyBound = this.LateBound,
             LateBound = new BoundingValue { Timestamp = target }
         };
     }
     return retval;
 }