/// <summary> /// Create interval, parsing from string form: /// <p> /// Form can be one of: /// <ul> /// <li>[<time>, <time>]</li> /// <li><time>,<time></li> /// </ul> /// </summary> /// <param name='interval'> /// Interval. /// </param> /// <exception cref='Exception'> /// Represents errors that occur during application execution. /// </exception> public ZTimeRange(string interval) { int isplit = interval.IndexOf(','); if (isplit == -1) { throw new Exception("time interval not in proper format: " + interval); } string sstart = interval.Substring(0, isplit).Trim(); string send = interval.Substring(isplit + 1).Trim(); if (sstart[0] == '[') { sstart = sstart.Substring(1); } if (send[send.Length - 1] == ']') { send = send.Substring(0, send.Length - 1); } _start = new ZTime(sstart); _end = new ZTime(send); Debug.Assert(_end.MilliSecond >= _start.MilliSecond); }
/// <summary> /// etermine if time after time-interval /// </summary> /// <param name='time'> /// time to consider /// </param> public bool After(ZTime time) { return(_end < time); }
/// <summary> /// Create interval spanning start to end times /// </summary> /// <param name='start'> /// Start time. /// </param> /// <param name='end'> /// End time. /// </param> public ZTimeRange(ZTime start, ZTime end) { _start = start; _end = end; Debug.Assert(end.MilliSecond >= start.MilliSecond); }
/// <summary> /// Determine if time within time-interval /// </summary> /// <param name='time'> /// time to consider /// </param> public bool Within(ZTime time) { return(_start <= time && _end >= time); }
/// <summary> /// Determine if time before time-interval /// </summary> /// <param name='time'> /// time to consider /// </param> public bool Before(ZTime time) { return(_start > time); }
/// <summary> /// Determine if time for given clock time within time-interval /// </summary> /// <param name='clock'> /// clock stamp from which time is extracted (in local timezone) /// </param> public bool Within(long clock) { return(Within(ZTime.TimeOf(clock))); }
// Operations /// <summary> /// Determine if time for given date within time-interval /// </summary> /// <param name='date'> /// date from which time is extracted (in local timezone) /// </param> public bool Within(ZDateTime date) { return(Within(ZTime.TimeOf(date))); }
public override bool Equals(object obj) { ZTime o = (ZTime)obj; return(_time == o._time); }
/// <summary> /// Provide the difference Ta and Tb in milliseconds (Ta - Tb). /// </summary> /// <param name='Ta'> /// Ta. /// </param> /// <param name='Tb'> /// Tb. /// </param> public static long Difference(ZTime Ta, ZTime Tb) { return(Ta._time - Tb._time); }
/// <summary> /// Provide offset in milliseconds from other time (if this time is > other will be +, otherwise -) /// </summary> /// <returns> /// Millisecond difference /// </returns> /// <param name='other'> /// Other time /// </param> public long OffsetFrom(ZTime other) { return(Difference(this, other)); }