Example #1
0
        /// <summary>
        /// 获取某个时间段内,不包括数据的时间段集合
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List <Tuple <DateTime, DateTime> > GetNoValueOffsets(DateTime startTime, DateTime endTime)
        {
            List <Tuple <DateTime, DateTime> > re = new List <Tuple <DateTime, DateTime> >();
            DateTime            stime             = startTime;
            List <DateTimeSpan> dtmp = new List <DateTimeSpan>();
            DateTimeSpan        ddt  = new DateTimeSpan()
            {
                Start = startTime, End = endTime
            };

            foreach (var vv in mTimeOffsets)
            {
                DateTimeSpan dts = new DateTimeSpan()
                {
                    Start = vv.Key, End = vv.Value.Item3
                };
                dts = dts.Cross(ddt);
                if (!dts.IsEmpty())
                {
                    dtmp.Add(dts);
                }
            }

            foreach (var vv in dtmp)
            {
                if (vv.Start > stime)
                {
                    re.Add(new Tuple <DateTime, DateTime>(stime, vv.Start));
                }
                stime = vv.End;
            }
            return(re);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public DateTimeSpan Cross(DateTimeSpan target)
        {
            DateTime stime = Max(target.Start, this.Start);
            DateTime etime = Min(target.End, this.End);

            if (etime < stime)
            {
                return(Empty);
            }
            else
            {
                return(new DateTimeSpan()
                {
                    Start = stime, End = etime
                });
            }
        }