Пример #1
0
        // ----------------------------------------------------------------------
        public void TimePeriodCollectionSample()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            DateTime testDay = new DateTime(2010, 7, 23);

            // --- items ---
            timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 8), TimeTrim.Hour(testDay, 11)));
            timePeriods.Add(new TimeBlock(TimeTrim.Hour(testDay, 10), Duration.Hours(3)));
            timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 16, 15), TimeTrim.Hour(testDay, 18, 45)));
            timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 14), TimeTrim.Hour(testDay, 15, 30)));
            Console.WriteLine("TimePeriodCollection: " + timePeriods);
            // > TimePeriodCollection: Count = 4; 23.07.2010 08:00:00 - 18:45:00 | 0.10:45
            Console.WriteLine("TimePeriodCollection.Items");
            foreach (ITimePeriod timePeriod in timePeriods)
            {
                Console.WriteLine("Item: " + timePeriod);
            }
            // > Item: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Item: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00
            // > Item: 23.07.2010 16:15:00 - 18:45:00 | 02:30:00
            // > Item: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00

            // --- intersection by moment ---
            DateTime intersectionMoment = new DateTime(2010, 7, 23, 10, 30, 0);
            ITimePeriodCollection momentIntersections = timePeriods.IntersectionPeriods(intersectionMoment);

            Console.WriteLine("TimePeriodCollection.IntesectionPeriods of " + intersectionMoment);
            // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 10:30:00
            foreach (ITimePeriod momentIntersection in momentIntersections)
            {
                Console.WriteLine("Intersection: " + momentIntersection);
            }
            // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00

            // --- intersection by period ---
            TimeRange             intersectionPeriod  = new TimeRange(TimeTrim.Hour(testDay, 9), TimeTrim.Hour(testDay, 14, 30));
            ITimePeriodCollection periodIntersections = timePeriods.IntersectionPeriods(intersectionPeriod);

            Console.WriteLine("TimePeriodCollection.IntesectionPeriods of " + intersectionPeriod);
            // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 09:00:00 - 14:30:00 | 0.05:30
            foreach (ITimePeriod periodIntersection in periodIntersections)
            {
                Console.WriteLine("Intersection: " + periodIntersection);
            }
            // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00
            // > Intersection: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00
        }         // TimePeriodCollectionSample
Пример #2
0
        public void IntersectionPeriodsTimePeriodTest()
        {
            var now        = ClockProxy.Clock.Now;
            var timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
            var timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
            var timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
            var timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 13));
            var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17));

            var timePeriods = new TimePeriodCollection
            {
                timeRange1,
                timeRange2,
                timeRange3,
                timeRange4,
                timeRange5
            };

            timePeriods.IntersectionPeriods(timeRange1).Count().Should().Be(5);
            timePeriods.IntersectionPeriods(timeRange2).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange3).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange4).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange5).Count().Should().Be(3);

            var test1          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
            var insidePeriods1 = timePeriods.IntersectionPeriods(test1).ToList();

            insidePeriods1.Count.Should().Be(0);

            var test2          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            var insidePeriods2 = timePeriods.IntersectionPeriods(test2).ToList();

            insidePeriods2.Count.Should().Be(0);

            var test3          = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11));
            var insidePeriods3 = timePeriods.IntersectionPeriods(test3).ToList();

            insidePeriods3.Count.Should().Be(3);

            var test4          = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
            var insidePeriods4 = timePeriods.IntersectionPeriods(test4).ToList();

            insidePeriods4.Count.Should().Be(3);
        }
Пример #3
0
        public void IntersectionPeriodsTimePeriodTest()
        {
            DateTime  now        = ClockProxy.Clock.Now;
            TimeRange timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
            TimeRange timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
            TimeRange timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
            TimeRange timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 13));
            TimeRange timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17));

            TimePeriodCollection timePeriods = new TimePeriodCollection();

            timePeriods.Add(timeRange1);
            timePeriods.Add(timeRange2);
            timePeriods.Add(timeRange3);
            timePeriods.Add(timeRange4);
            timePeriods.Add(timeRange5);

            Assert.Equal(5, timePeriods.IntersectionPeriods(timeRange1).Count);
            Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange2).Count);
            Assert.Equal(4, timePeriods.IntersectionPeriods(timeRange3).Count);
            Assert.Equal(4, timePeriods.IntersectionPeriods(timeRange4).Count);
            Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange5).Count);

            ITimeRange            test1          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
            ITimePeriodCollection insidePeriods1 = timePeriods.IntersectionPeriods(test1);

            Assert.Equal(0, insidePeriods1.Count);

            ITimeRange            test2          = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            ITimePeriodCollection insidePeriods2 = timePeriods.IntersectionPeriods(test2);

            Assert.Equal(0, insidePeriods2.Count);

            TimeRange             test3          = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11));
            ITimePeriodCollection insidePeriods3 = timePeriods.IntersectionPeriods(test3);

            Assert.Equal(3, insidePeriods3.Count);

            TimeRange             test4          = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
            ITimePeriodCollection insidePeriods4 = timePeriods.IntersectionPeriods(test4);

            Assert.Equal(3, insidePeriods4.Count);
        }         // IntersectionPeriodsTimePeriodTest
Пример #4
0
        public void IntersectionPeriodsDateTimeTest()
        {
            DateTime  now        = ClockProxy.Clock.Now;
            TimeRange timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
            TimeRange timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
            TimeRange timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
            TimeRange timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 14));
            TimeRange timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 16), new DateTime(now.Year, now.Month, 17));

            TimePeriodCollection timePeriods = new TimePeriodCollection();

            timePeriods.Add(timeRange1);
            timePeriods.Add(timeRange2);
            timePeriods.Add(timeRange3);
            timePeriods.Add(timeRange4);
            timePeriods.Add(timeRange5);

            Assert.Equal(1, timePeriods.IntersectionPeriods(timeRange1.Start).Count);
            Assert.Equal(1, timePeriods.IntersectionPeriods(timeRange1.End).Count);

            Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange2.Start).Count);
            Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange2.End).Count);

            Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange3.Start).Count);
            Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange3.End).Count);

            Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange4.Start).Count);
            Assert.Equal(3, timePeriods.IntersectionPeriods(timeRange4.End).Count);

            Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange5.Start).Count);
            Assert.Equal(2, timePeriods.IntersectionPeriods(timeRange5.End).Count);

            DateTime test1 = timeRange1.Start.AddMilliseconds(-1);
            ITimePeriodCollection insidePeriods1 = timePeriods.IntersectionPeriods(test1);

            Assert.Equal(0, insidePeriods1.Count);

            DateTime test2 = timeRange1.End.AddMilliseconds(1);
            ITimePeriodCollection insidePeriods2 = timePeriods.IntersectionPeriods(test2);

            Assert.Equal(0, insidePeriods2.Count);

            DateTime test3 = new DateTime(now.Year, now.Month, 12);
            ITimePeriodCollection insidePeriods3 = timePeriods.IntersectionPeriods(test3);

            Assert.Equal(2, insidePeriods3.Count);

            DateTime test4 = new DateTime(now.Year, now.Month, 14);
            ITimePeriodCollection insidePeriods4 = timePeriods.IntersectionPeriods(test4);

            Assert.Equal(3, insidePeriods4.Count);
        }         // IntersectionPeriodsDateTimeTest
        public void IntersectionPeriodsTimePeriodTest() {
            var now = ClockProxy.Clock.Now;
            var timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
            var timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
            var timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
            var timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 13));
            var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17));

            var timePeriods = new TimePeriodCollection
                              {
                                  timeRange1,
                                  timeRange2,
                                  timeRange3,
                                  timeRange4,
                                  timeRange5
                              };

            timePeriods.IntersectionPeriods(timeRange1).Count().Should().Be(5);
            timePeriods.IntersectionPeriods(timeRange2).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange3).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange4).Count().Should().Be(4);
            timePeriods.IntersectionPeriods(timeRange5).Count().Should().Be(3);

            var test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
            var insidePeriods1 = timePeriods.IntersectionPeriods(test1).ToList();
            insidePeriods1.Count.Should().Be(0);

            var test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
            var insidePeriods2 = timePeriods.IntersectionPeriods(test2).ToList();
            insidePeriods2.Count.Should().Be(0);

            var test3 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11));
            var insidePeriods3 = timePeriods.IntersectionPeriods(test3).ToList();
            insidePeriods3.Count.Should().Be(3);

            var test4 = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
            var insidePeriods4 = timePeriods.IntersectionPeriods(test4).ToList();
            insidePeriods4.Count.Should().Be(3);
        }
        public void IntersectionPeriodsDateTimeTest() {
            var now = ClockProxy.Clock.Now;
            var timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
            var timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
            var timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
            var timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 14));
            var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 16), new DateTime(now.Year, now.Month, 17));

            TimePeriodCollection timePeriods = new TimePeriodCollection
                                               {
                                                   timeRange1,
                                                   timeRange2,
                                                   timeRange3,
                                                   timeRange4,
                                                   timeRange5
                                               };

            timePeriods.IntersectionPeriods(timeRange1.Start).Count().Should().Be(1);
            timePeriods.IntersectionPeriods(timeRange1.End).Count().Should().Be(1);

            timePeriods.IntersectionPeriods(timeRange2.Start).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange2.End).Count().Should().Be(3);

            timePeriods.IntersectionPeriods(timeRange3.Start).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange3.End).Count().Should().Be(2);

            timePeriods.IntersectionPeriods(timeRange4.Start).Count().Should().Be(2);
            timePeriods.IntersectionPeriods(timeRange4.End).Count().Should().Be(3);

            timePeriods.IntersectionPeriods(timeRange5.Start).Count().Should().Be(2);
            timePeriods.IntersectionPeriods(timeRange5.End).Count().Should().Be(2);

            var test1 = timeRange1.Start.AddMilliseconds(-1);
            var insidePeriods1 = timePeriods.IntersectionPeriods(test1).ToList();
            insidePeriods1.Count.Should().Be(0);

            DateTime test2 = timeRange1.End.AddMilliseconds(1);
            var insidePeriods2 = timePeriods.IntersectionPeriods(test2).ToList();
            insidePeriods2.Count.Should().Be(0);

            DateTime test3 = new DateTime(now.Year, now.Month, 12);
            var insidePeriods3 = timePeriods.IntersectionPeriods(test3).ToList();
            insidePeriods3.Count.Should().Be(2);

            DateTime test4 = new DateTime(now.Year, now.Month, 14);
            var insidePeriods4 = timePeriods.IntersectionPeriods(test4).ToList();
            insidePeriods4.Count.Should().Be(3);
        }
Пример #7
0
        public void IntersectionPeriodsDateTimeTest()
        {
            var now        = ClockProxy.Clock.Now;
            var timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
            var timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
            var timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
            var timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 14));
            var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 16), new DateTime(now.Year, now.Month, 17));

            TimePeriodCollection timePeriods = new TimePeriodCollection
            {
                timeRange1,
                timeRange2,
                timeRange3,
                timeRange4,
                timeRange5
            };

            timePeriods.IntersectionPeriods(timeRange1.Start).Count().Should().Be(1);
            timePeriods.IntersectionPeriods(timeRange1.End).Count().Should().Be(1);

            timePeriods.IntersectionPeriods(timeRange2.Start).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange2.End).Count().Should().Be(3);

            timePeriods.IntersectionPeriods(timeRange3.Start).Count().Should().Be(3);
            timePeriods.IntersectionPeriods(timeRange3.End).Count().Should().Be(2);

            timePeriods.IntersectionPeriods(timeRange4.Start).Count().Should().Be(2);
            timePeriods.IntersectionPeriods(timeRange4.End).Count().Should().Be(3);

            timePeriods.IntersectionPeriods(timeRange5.Start).Count().Should().Be(2);
            timePeriods.IntersectionPeriods(timeRange5.End).Count().Should().Be(2);

            var test1          = timeRange1.Start.AddMilliseconds(-1);
            var insidePeriods1 = timePeriods.IntersectionPeriods(test1).ToList();

            insidePeriods1.Count.Should().Be(0);

            DateTime test2          = timeRange1.End.AddMilliseconds(1);
            var      insidePeriods2 = timePeriods.IntersectionPeriods(test2).ToList();

            insidePeriods2.Count.Should().Be(0);

            DateTime test3          = new DateTime(now.Year, now.Month, 12);
            var      insidePeriods3 = timePeriods.IntersectionPeriods(test3).ToList();

            insidePeriods3.Count.Should().Be(2);

            DateTime test4          = new DateTime(now.Year, now.Month, 14);
            var      insidePeriods4 = timePeriods.IntersectionPeriods(test4).ToList();

            insidePeriods4.Count.Should().Be(3);
        }