Beispiel #1
0
        public DateList FilterWithList(DateList dl)
        {
            var ret = new DateList();

            foreach (var d in List)
            {
                foreach (var df in dl.List)
                {
                    if (d.DateFrom > df.DateTo || d.DateTo < df.DateFrom)
                    {
                        continue;
                    }
                    var nd = new DatesFromTo(d);
                    if (nd.DateFrom < df.DateFrom)
                    {
                        nd.DateFrom = df.DateFrom;
                    }
                    if (nd.DateTo > df.DateTo)
                    {
                        nd.DateTo = df.DateTo;
                    }
                    ret.List.Add(nd);
                }
            }
            return(ret);
        }
Beispiel #2
0
        public DateList SubtractFromDatesGoodList(DateTime dt1, DateTime dt2)
        {
            var ret = new DateList();

            ret.List.Add(new DatesFromTo(dt1, dt2));

            foreach (var d in List)
            {
                if (d.DateFrom > dt2 || d.DateTo < dt1)
                {
                    continue;
                }
                if (ret.List.Count == 0)
                {
                    break;
                }
                var cd = ret.List[ret.List.Count - 1];
                if (cd.DateFrom >= d.DateFrom && cd.DateTo <= d.DateTo)
                {
                    ret.List.RemoveAt(ret.List.Count - 1);
                    break;
                }
                if (cd.DateFrom < d.DateFrom && cd.DateTo > d.DateTo)
                {
                    var nd = new DatesFromTo(cd);
                    ret.List.Add(nd);
                    cd.DateTo   = d.DateFrom.AddDays(-1);
                    nd.DateFrom = d.DateTo.AddDays(1);
                    break;
                }
                if (cd.DateFrom < d.DateFrom)
                {
                    cd.DateTo = d.DateFrom.AddDays(-1);
                    break;
                }
                else
                {
                    cd.DateFrom = d.DateTo.AddDays(1);
                }
            }

            return(ret);
        }
Beispiel #3
0
        public DateList FilterWithDates(DateTime dt1, DateTime dt2)
        {
            var ret = new DateList();

            foreach (var d in List)
            {
                if (d.DateFrom > dt2 || d.DateTo < dt1)
                {
                    continue;
                }
                var nd = new DatesFromTo(d);
                if (nd.DateFrom < dt1)
                {
                    nd.DateFrom = dt1;
                }
                if (nd.DateTo > dt2)
                {
                    nd.DateTo = dt2;
                }
                ret.List.Add(nd);
            }
            return(ret);
        }
Beispiel #4
0
        public DateList SubtractDates(DateTime dt1, DateTime dt2)
        {
            var ret = new DateList();

            foreach (var d in List)
            {
                if (d.DateFrom >= dt1 && d.DateTo <= dt2)
                {
                    continue;
                }
                var nd = new DatesFromTo(d);
                ret.List.Add(nd);
                if (d.DateFrom > dt2 || d.DateTo < dt1)
                {
                    continue;
                }
                if (d.DateFrom < dt1 && d.DateTo > dt2)
                {
                    nd.DateTo   = dt1.AddDays(-1);
                    nd          = new DatesFromTo(d);
                    nd.DateFrom = dt2.AddDays(1);
                    ret.List.Add(nd);
                    continue;
                }
                if (d.DateFrom >= dt1)
                {
                    nd.DateFrom = dt2.AddDays(1);
                    continue;
                }
                if (d.DateTo <= dt2)
                {
                    nd.DateTo = dt1.AddDays(-1);
                    continue;
                }
            }
            return(ret);
        }
Beispiel #5
0
 public void SetFrom(DatesFromTo d)
 {
     DateFrom = d.DateFrom;
     DateTo   = d.DateTo;
 }
Beispiel #6
0
 public DatesFromTo(DatesFromTo d)
 {
     DateFrom = d.DateFrom;
     DateTo   = d.DateTo;
 }
Beispiel #7
0
        public DateList SubtractList_ForGoodLists(DateList dl)
        {
            if (dl.List.Count == 0 || List.Count == 0)
            {
                return(new DateList(this));
            }

            var ret = new DateList();

            int ti  = 0;
            int si  = 0;
            var td1 = new DatesFromTo(List[0]);
            var sd1 = dl.List[0];

            DatesFromTo cd = null;

            while (true)
            {
                if (sd1 != null && td1.DateFrom > sd1.DateTo)
                {
                    if (si == dl.List.Count - 1)
                    {
                        sd1 = null;
                        continue;
                    }
                    si++;
                    sd1 = dl.List[si];
                    continue;
                }
                if (sd1 == null || td1.DateTo < sd1.DateFrom)
                {
                    ret.List.Add(td1);
                    if (ti == List.Count - 1)
                    {
                        break;
                    }
                    ti++;
                    td1 = new DatesFromTo(List[ti]);
                    continue;
                }
                if (td1.DateFrom >= sd1.DateFrom && td1.DateTo <= sd1.DateTo)
                {
                    if (ti == List.Count - 1)
                    {
                        break;
                    }
                    ti++;
                    td1.SetFrom(List[ti]);
                    continue;
                }
                if (td1.DateFrom >= sd1.DateFrom && td1.DateTo > sd1.DateTo)
                {
                    td1.DateFrom = sd1.DateTo.AddDays(1);
                    continue;
                }
                if (td1.DateFrom < sd1.DateFrom && td1.DateTo <= sd1.DateTo)
                {
                    td1.DateTo = sd1.DateFrom.AddDays(-1);
                    ret.List.Add(td1);
                    if (ti == List.Count - 1)
                    {
                        break;
                    }
                    ti++;
                    td1 = new DatesFromTo(List[ti]);
                    continue;
                }
                if (td1.DateFrom < sd1.DateFrom && td1.DateTo > sd1.DateTo)
                {
                    cd        = new DatesFromTo(td1);
                    cd.DateTo = sd1.DateFrom.AddDays(-1);
                    ret.List.Add(cd);
                    td1.DateFrom = sd1.DateTo.AddDays(1);
                    continue;
                }
            }

            return(ret);
        }