Example #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);
        }
Example #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 (From < latest)
            {
                DateTime target = From + new TimeSpan(MillisecondsToTicks(inc));
                retval = new BackwardTimeSlice
                {
                    From       = target,
                    To         = this.From,
                    Incomplete = false,
                    EarlyBound = this.LateBound,
                    LateBound  = new BoundingValue {
                        Timestamp = target
                    }
                };
            }
            return(retval);
        }
Example #3
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;
 }
Example #4
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 (From < latest)
     {
         DateTime target = From + new TimeSpan(MillisecondsToTicks(inc));
         retval = new BackwardTimeSlice
         {
             From = target,
             To = this.From,
             Incomplete = false,
             EarlyBound = this.LateBound,
             LateBound = new BoundingValue { Timestamp = target }
         };
     }
     return retval;
 }