Ejemplo n.º 1
0
        public void Union(DateRange intv)
        {
            int i      = 0;
            int j      = 0;
            var iCount = _intervals.Count;
            var jCount = intv._intervals.Count;
            var union  = new List <DateInterval>();

            DateTime intStart = DateTime.MaxValue;
            DateTime intEnd   = DateTime.MaxValue;

            while (i < _intervals.Count || j < intv._intervals.Count)
            {
                DateInterval next;
                if (i < iCount && j < jCount)
                {
                    var iR = _intervals[i];
                    var jR = intv._intervals[j];
                    if (iR.Start < jR.Start)
                    {
                        next = iR;
                        i++;
                    }
                    else
                    {
                        next = jR;
                        j++;
                    }
                }
                else if (i < iCount)
                {
                    next = _intervals[i];
                    i++;
                }
                else
                {
                    next = intv._intervals[j];
                    j++;
                }

                if (next.Start > intEnd)
                {
                    union.Add(new DateInterval(intStart, intEnd));
                    intStart = next.Start;
                }
                else
                {
                    intStart = Min(next.Start, intStart);
                }

                if (i + j > 1)
                {
                    intEnd = Max(intEnd, next.End);
                }
                else
                {
                    // First step.
                    intEnd = next.End;
                }
            }
            if (intStart < intEnd)
            {
                union.Add(new DateInterval(intStart, intEnd));
            }
            _intervals = union;
        }
Ejemplo n.º 2
0
 public DateRange(DateRange timestamps)
 {
     _intervals = new List <DateInterval>(timestamps._intervals);
 }