Ejemplo n.º 1
0
        public void CalendarTest() {
            var timeCalendar = new TimeCalendar();
            var timeRange = new CalendarTimeRange(TimeRange.Anytime, timeCalendar);

            timeRange.TimeCalendar.Should().Be(timeCalendar);
            timeRange.IsAnytime.Should().Be.True();
        }
Ejemplo n.º 2
0
        // ----------------------------------------------------------------------
        public void CalendarPeriodCollectorSample()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(YearMonth.January);               // only Januaries
            filter.WeekDays.Add(DayOfWeek.Friday);              // only Fridays
            filter.CollectingHours.Add(new HourRange(8, 18));   // working hours

            CalendarTimeRange testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            Console.WriteLine("Calendar period collector of period: " + testPeriod);
            // > Calendar period collector of period: 01.01.2010 00:00:00 - 30.12.2011 23:59:59 | 728.23:59

            CalendarPeriodCollector collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectHours();
            foreach (ITimePeriod period in collector.Periods)
            {
                Console.WriteLine("Period: " + period);
            }
            // > Period: 01.01.2010; 08:00 - 17:59 | 0.09:59
            // > Period: 08.01.2010; 08:00 - 17:59 | 0.09:59
            // > Period: 15.01.2010; 08:00 - 17:59 | 0.09:59
            // > Period: 22.01.2010; 08:00 - 17:59 | 0.09:59
            // > Period: 29.01.2010; 08:00 - 17:59 | 0.09:59
            // > Period: 07.01.2011; 08:00 - 17:59 | 0.09:59
            // > Period: 14.01.2011; 08:00 - 17:59 | 0.09:59
            // > Period: 21.01.2011; 08:00 - 17:59 | 0.09:59
            // > Period: 28.01.2011; 08:00 - 17:59 | 0.09:59
        }         // CalendarPeriodCollectorSample
Ejemplo n.º 3
0
        public void CalendarGetGapTest()
        {
            // simmulation of some reservations
            TimePeriodCollection periods = new TimePeriodCollection();

            periods.Add(new Days(2011, 3, 7, 2));
            periods.Add(new Days(2011, 3, 16, 2));

            // the overall search range
            CalendarTimeRange limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21));
            Days days = new Days(limits.Start, limits.Duration.Days + 1);
            ITimePeriodCollection dayList = days.GetDays();

            foreach (Day day in dayList)
            {
                if (!limits.HasInside(day))
                {
                    continue;                     // outside of the search scope
                }
                if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday)
                {
                    periods.Add(day);                       // // exclude weekend day
                }
            }

            TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(new TimeCalendar());
            ITimePeriodCollection         gaps          = gapCalculator.GetGaps(periods, limits);

            Assert.Equal(4, gaps.Count);
            Assert.True(gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), Duration.Days(1))));
            Assert.True(gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), Duration.Days(3))));
            Assert.True(gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), Duration.Days(2))));
            Assert.True(gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), Duration.Days(1))));
        } // CalendarGetGapTest
Ejemplo n.º 4
0
        public void CalendarTest()
        {
            TimeCalendar      calendar          = new TimeCalendar();
            CalendarTimeRange calendarTimeRange = new CalendarTimeRange(TimeRange.Anytime, calendar);

            Assert.Equal(calendarTimeRange.Calendar, calendar);
        }         // CalendarTest
        public void CollectHoursTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(YearMonth.January);
            filter.WeekDays.Add(DayOfWeek.Friday);
            filter.CollectingHours.Add(new HourRange(8, 18));

            CalendarTimeRange testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            CalendarPeriodCollector collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectHours();

            Assert.AreEqual(collector.Periods.Count, 9);
            Assert.IsTrue(collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 01, 8, 0, 0), new DateTime(2010, 1, 01, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 08, 8, 0, 0), new DateTime(2010, 1, 08, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[2].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 15, 8, 0, 0), new DateTime(2010, 1, 15, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[3].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 22, 8, 0, 0), new DateTime(2010, 1, 22, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[4].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 29, 8, 0, 0), new DateTime(2010, 1, 29, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[5].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 07, 8, 0, 0), new DateTime(2011, 1, 07, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[6].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 14, 8, 0, 0), new DateTime(2011, 1, 14, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[7].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 21, 8, 0, 0), new DateTime(2011, 1, 21, 18, 0, 0))));
            Assert.IsTrue(collector.Periods[8].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 28, 8, 0, 0), new DateTime(2011, 1, 28, 18, 0, 0))));
        }         // CollectHoursTest
        public void CollectYearsTest()
        {
            var filter = new CalendarPeriodCollectorFilter();

            filter.Years.Add(2006);
            filter.Years.Add(2007);
            filter.Years.Add(2012);

            var testPeriod = new CalendarTimeRange(new DateTime(2001, 1, 1), new DateTime(2019, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectYears();

            if (IsDebugEnabled)
            {
                log.Debug("CollectYears... Period=" + collector.Periods.CollectionToString());
            }

            collector.Periods.Count.Should().Be(filter.Years.Count);

            for (var i = 0; i < collector.Periods.Count; i++)
            {
                collector.Periods[i].IsSamePeriod(new YearRange(filter.Years.ElementAt(i)));
            }
        }
        public void CollectDaysTest()
        {
            var filter = new CalendarPeriodCollectorFilter();

            //! 1월의 금요일만 추출
            filter.Months.Add(January);
            filter.WeekDays.Add(DayOfWeek.Friday);

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectDays();

            if (IsDebugEnabled)
            {
                foreach (var period in collector.Periods)
                {
                    log.Debug("CollectDays... Period=" + period);
                }
            }

            collector.Periods.Count.Should().Be(9);

            collector.Periods[0].IsSamePeriod(new DayRange(new DateTime(2010, 1, 1))).Should().Be.True();
            collector.Periods[1].IsSamePeriod(new DayRange(new DateTime(2010, 1, 8))).Should().Be.True();
            collector.Periods[2].IsSamePeriod(new DayRange(new DateTime(2010, 1, 15))).Should().Be.True();
            collector.Periods[3].IsSamePeriod(new DayRange(new DateTime(2010, 1, 22))).Should().Be.True();
            collector.Periods[4].IsSamePeriod(new DayRange(new DateTime(2010, 1, 29))).Should().Be.True();

            collector.Periods[5].IsSamePeriod(new DayRange(new DateTime(2011, 1, 7))).Should().Be.True();
            collector.Periods[6].IsSamePeriod(new DayRange(new DateTime(2011, 1, 14))).Should().Be.True();
            collector.Periods[7].IsSamePeriod(new DayRange(new DateTime(2011, 1, 21))).Should().Be.True();
            collector.Periods[8].IsSamePeriod(new DayRange(new DateTime(2011, 1, 28))).Should().Be.True();
        }
        public void CollectDaysTest() {
            var filter = new CalendarPeriodCollectorFilter();

            //! 1월의 금요일만 추출
            filter.Months.Add(January);
            filter.WeekDays.Add(DayOfWeek.Friday);

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);
            collector.CollectDays();

            if(IsDebugEnabled) {
                foreach(var period in collector.Periods)
                    log.Debug("CollectDays... Period=" + period);
            }

            collector.Periods.Count.Should().Be(9);

            collector.Periods[0].IsSamePeriod(new DayRange(new DateTime(2010, 1, 1))).Should().Be.True();
            collector.Periods[1].IsSamePeriod(new DayRange(new DateTime(2010, 1, 8))).Should().Be.True();
            collector.Periods[2].IsSamePeriod(new DayRange(new DateTime(2010, 1, 15))).Should().Be.True();
            collector.Periods[3].IsSamePeriod(new DayRange(new DateTime(2010, 1, 22))).Should().Be.True();
            collector.Periods[4].IsSamePeriod(new DayRange(new DateTime(2010, 1, 29))).Should().Be.True();

            collector.Periods[5].IsSamePeriod(new DayRange(new DateTime(2011, 1, 7))).Should().Be.True();
            collector.Periods[6].IsSamePeriod(new DayRange(new DateTime(2011, 1, 14))).Should().Be.True();
            collector.Periods[7].IsSamePeriod(new DayRange(new DateTime(2011, 1, 21))).Should().Be.True();
            collector.Periods[8].IsSamePeriod(new DayRange(new DateTime(2011, 1, 28))).Should().Be.True();
        }
Ejemplo n.º 9
0
        public void Excluded_slot()
        {
            var filter = new CalendarPeriodCollectorFilter();

            filter.AddWorkingWeekDays();
            filter.CollectingHours.Add(new HourRange(8, 12));  // working hours
            filter.CollectingHours.Add(new HourRange(14, 18)); // working hours

            filter.ExcludePeriods.Add(new CalendarTimeRange(
                                          DateTime.Parse("2014-07-15T09:30"),
                                          DateTime.Parse("2014-07-15T10:30")
                                          ));

            var testPeriod = new CalendarTimeRange(new DateTime(2014, 7, 14), new DateTime(2014, 7, 31));

            Console.WriteLine("Calendar period collector of period: " + testPeriod);

            var collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectHours();
            foreach (ITimePeriod period in collector.Periods)
            {
                Console.WriteLine("Period: " + period);
            }

            Assert.IsFalse(collector.Periods.Any(x => x.HasInside(DateTime.Parse("2014-07-15T10:00"))));
            Assert.IsTrue(collector.Periods.Any(x => x.HasInside(DateTime.Parse("2014-07-15T09:00"))));
            Assert.IsTrue(collector.Periods.Any(x => x.HasInside(DateTime.Parse("2014-07-15T11:00"))));
        }
Ejemplo n.º 10
0
        public void CalendarGetGapTest()
        {
            // simmulation of some reservations
            var periods = new TimePeriodCollection
            {
                new DayRangeCollection(2011, 3, 7, 2),
                new DayRangeCollection(2011, 3, 16, 2)
            };

            // the overall search range
            var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21));
            var days   = new DayRangeCollection(limits.Start, limits.Duration.Days + 1);

            // limits의 내부이고, 주말인 DayRange를 추가합니다.
            var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd());

            periods.AddAll(excludeDays.Cast <ITimePeriod>());

            var gapCalculator = new TimeGapCalculator <TimeRange>(new TimeCalendar());
            var gaps          = gapCalculator.GetGaps(periods, limits);

            gaps.Count.Should().Be(4);
            gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True();
            gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True();
            gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True();
            gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True();
        }
Ejemplo n.º 11
0
        public void GenerateCategories_YearWeek() {
            var period = new CalendarTimeRange(new DateTime(2008, 7, 12), new DateTime(2011, 2, 12), TimeCalendar.NewEmptyOffset());
            var chart = new GanttChart();

            GanttUtil.GenerateCategories(chart.CategoriesList, period, PeriodFlags.YearWeek);
            chart.SetExportInServer();

            if(IsDebugEnabled)
                log.Debug("chart=" + chart.GetDataXml(true));
        }
        public void CollectHoursTest()
        {
            //! 1월의 금요일의 8:00~18:00 까지 기간만을 계산한다.
            var filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(January);
            filter.WeekDays.Add(DayOfWeek.Friday);
            filter.CollectingHours.Add(new HourRangeInDay(8, 18));

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectHours();

            Assert.AreEqual(collector.Periods.Count, 9);
            Assert.IsTrue(
                collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 01, 8, 0, 0),
                                                                        new DateTime(2010, 1, 01, 18, 0, 0))),
                collector.Periods[0].ToString());
            Assert.IsTrue(
                collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 08, 8, 0, 0),
                                                                        new DateTime(2010, 1, 08, 18, 0, 0))),
                collector.Periods[1].ToString());
            Assert.IsTrue(
                collector.Periods[2].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 15, 8, 0, 0),
                                                                        new DateTime(2010, 1, 15, 18, 0, 0))),
                collector.Periods[2].ToString());
            Assert.IsTrue(
                collector.Periods[3].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 22, 8, 0, 0),
                                                                        new DateTime(2010, 1, 22, 18, 0, 0))),
                collector.Periods[3].ToString());
            Assert.IsTrue(
                collector.Periods[4].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 29, 8, 0, 0),
                                                                        new DateTime(2010, 1, 29, 18, 0, 0))),
                collector.Periods[4].ToString());
            Assert.IsTrue(
                collector.Periods[5].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 07, 8, 0, 0),
                                                                        new DateTime(2011, 1, 07, 18, 0, 0))),
                collector.Periods[5].ToString());
            Assert.IsTrue(
                collector.Periods[6].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 14, 8, 0, 0),
                                                                        new DateTime(2011, 1, 14, 18, 0, 0))),
                collector.Periods[6].ToString());
            Assert.IsTrue(
                collector.Periods[7].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 21, 8, 0, 0),
                                                                        new DateTime(2011, 1, 21, 18, 0, 0))),
                collector.Periods[7].ToString());
            Assert.IsTrue(
                collector.Periods[8].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 28, 8, 0, 0),
                                                                        new DateTime(2011, 1, 28, 18, 0, 0))),
                collector.Periods[8].ToString());
        }
Ejemplo n.º 13
0
        public void GenerateCategories_YearWeek()
        {
            var period = new CalendarTimeRange(new DateTime(2008, 7, 12), new DateTime(2011, 2, 12), TimeCalendar.NewEmptyOffset());
            var chart  = new GanttChart();

            GanttUtil.GenerateCategories(chart.CategoriesList, period, PeriodFlags.YearWeek);
            chart.SetExportInServer();

            if (IsDebugEnabled)
            {
                log.Debug("chart=" + chart.GetDataXml(true));
            }
        }
        public void CollectMonthsTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(YearMonth.January);

            CalendarTimeRange testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            CalendarPeriodCollector collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectMonths();

            Assert.AreEqual(collector.Periods.Count, 2);
            Assert.IsTrue(collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2010, 2, 1))));
            Assert.IsTrue(collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 1), new DateTime(2011, 2, 1))));
        }         // CollectMonthsTest
        public void CollectMonthsTest() {
            var filter = new CalendarPeriodCollectorFilter();
            filter.Months.Add(January);

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);
            collector.CollectMonths();

            if(IsDebugEnabled)
                log.Debug("CollectMonths... Period=" + collector.Periods.CollectionToString());

            collector.Periods.Count.Should().Be(2);
            collector.Periods[0].IsSamePeriod(new MonthRange(2010, January)).Should().Be.True();
            collector.Periods[1].IsSamePeriod(new MonthRange(2011, January)).Should().Be.True();
        }
Ejemplo n.º 16
0
        // ----------------------------------------------------------------------
        public void TimeGapCalculatorSample()
        {
            // simulation of some reservations
            TimePeriodCollection reservations = new TimePeriodCollection();

            reservations.Add(new Days(2011, 3, 7, 2));
            reservations.Add(new Days(2011, 3, 16, 2));

            // the overall search range
            CalendarTimeRange searchLimits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21));

            // search the largest free time block
            ICalendarTimeRange largestFreeTimeBlock = FindLargestFreeTimeBlock(reservations, searchLimits);

            Console.WriteLine("Largest free time: " + largestFreeTimeBlock);
            // > Largest free time: 09.03.2011 00:00:00 - 11.03.2011 23:59:59 | 2.23:59
        }         // TimeGapCalculatorSample
        public void CollectHoursMissingLastPeriodTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(YearMonth.September);
            filter.WeekDays.Add(DayOfWeek.Monday);
            filter.WeekDays.Add(DayOfWeek.Tuesday);
            filter.WeekDays.Add(DayOfWeek.Wednesday);
            filter.WeekDays.Add(DayOfWeek.Thursday);
            filter.WeekDays.Add(DayOfWeek.Friday);
            filter.CollectingHours.Add(new HourRange(9, 17)); // working hours
            filter.ExcludePeriods.Add(new TimeBlock(new DateTime(2015, 9, 15, 00, 0, 0), new DateTime(2015, 9, 16, 0, 0, 0)));

            CalendarTimeRange       testPeriod = new CalendarTimeRange(new DateTime(2015, 9, 14, 9, 0, 0), new DateTime(2015, 9, 17, 18, 0, 0));
            CalendarPeriodCollector collector  = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectHours();
            Assert.Equal(3, collector.Periods.Count);
        } // CollectHoursMissingLastPeriodTest
        public void CollectYearsTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Years.Add(2006);
            filter.Years.Add(2007);
            filter.Years.Add(2012);

            CalendarTimeRange testPeriod = new CalendarTimeRange(new DateTime(2001, 1, 1), new DateTime(2019, 12, 31));

            CalendarPeriodCollector collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectYears();

            Assert.AreEqual(collector.Periods.Count, 3);
            Assert.IsTrue(collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2006, 1, 1), new DateTime(2007, 1, 1))));
            Assert.IsTrue(collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2007, 1, 1), new DateTime(2008, 1, 1))));
            Assert.IsTrue(collector.Periods[2].IsSamePeriod(new CalendarTimeRange(new DateTime(2012, 1, 1), new DateTime(2013, 1, 1))));
        }         // CollectYearsTest
        public void CollectYearsTest() {
            var filter = new CalendarPeriodCollectorFilter();

            filter.Years.Add(2006);
            filter.Years.Add(2007);
            filter.Years.Add(2012);

            var testPeriod = new CalendarTimeRange(new DateTime(2001, 1, 1), new DateTime(2019, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);
            collector.CollectYears();

            if(IsDebugEnabled)
                log.Debug("CollectYears... Period=" + collector.Periods.CollectionToString());

            collector.Periods.Count.Should().Be(filter.Years.Count);

            for(var i = 0; i < collector.Periods.Count; i++)
                collector.Periods[i].IsSamePeriod(new YearRange(filter.Years.ElementAt(i)));
        }
Ejemplo n.º 20
0
        protected override bool OnVisitDay(DayRange day, CalendarPeriodCollectorContext context)
        {
            if (IsDebugEnabled)
            {
                log.Debug("Day[{0}]를 탐색합니다...", day);
            }

            if (context.Scope != CalendarPeriodCollectorContext.CollectKind.Hour)
            {
                return(true); // continue
            }

            // all month
            if (Filter.CollectingHours.Count == 0)
            {
                var hours = day.GetHours().Where(h => IsMatchingHour(h, context) && CheckLimits(h));
                _periods.AddAll(hours.Cast <ITimePeriod>().AsEnumerable());
            }
            else if (IsMatchingDay(day, context))
            {
                var hours =
                    Filter.CollectingHours
                    .Select(hour => {
                    var startTime  = hour.Start.GetDateTime(day.Start);
                    var endTime    = hour.End.GetDateTime(day.Start);
                    var hourRanges = new CalendarTimeRange(startTime, endTime, day.TimeCalendar);

                    if (CheckExcludePeriods(hourRanges) && CheckLimits(hourRanges))
                    {
                        return((ITimePeriod)hourRanges);
                    }

                    return(null);
                })
                    .Where(h => h != null);

                _periods.AddAll(hours.AsEnumerable());
            }

            return(false); // abort
        }
        public void CollectMonthsTest()
        {
            var filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(January);

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectMonths();

            if (IsDebugEnabled)
            {
                log.Debug("CollectMonths... Period=" + collector.Periods.CollectionToString());
            }

            collector.Periods.Count.Should().Be(2);
            collector.Periods[0].IsSamePeriod(new MonthRange(2010, January)).Should().Be.True();
            collector.Periods[1].IsSamePeriod(new MonthRange(2011, January)).Should().Be.True();
        }
Ejemplo n.º 22
0
        public static double NetworkDays(DateTime start, DateTime end,
                                         IEnumerable <DateTime> holidays      = null,
                                         ITimePeriodCollection holidayPeriods = null)
        {
            var startDay = new Day(start < end ? start : end);
            var endDay   = new Day(end > start ? end : start);

            if (startDay.Equals(endDay))
            {
                return(0);
            }

            var filter = new CalendarPeriodCollectorFilter();

            filter.AddWorkingWeekDays();
            if (holidays != null)
            {
                foreach (DateTime holiday in holidays)
                {
                    filter.ExcludePeriods.Add(new Day(holiday));
                }
            }
            if (holidayPeriods != null)
            {
                filter.ExcludePeriods.AddAll(holidayPeriods);
            }

            var testPeriod = new CalendarTimeRange(start, end);
            var collector  = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectDays();

            var networkDays = 0.0d;

            foreach (ICalendarTimeRange period in collector.Periods)
            {
                networkDays += Math.Round(period.Duration.TotalDays, 2);
            }
            return(networkDays);
        }
Ejemplo n.º 23
0
        }         //    Intersector4

        // ----------------------------------------------------------------------
        public void TimeGapCalculator(int count)
        {
            // simulation of some reservations
            TimePeriodCollection reservations = new TimePeriodCollection();

            reservations.Add(new Days(2011, 3, 7, 2));
            reservations.Add(new Days(2011, 3, 16, 2));

            // the overall search range
            CalendarTimeRange searchLimits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21));

            // search the largest free time block
            Console.Write("TimeGapCalculator ({0:#,0}): ", count);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < count; i++)
            {
                FindLargestFreeTimeBlock(reservations, searchLimits);
            }
            stopwatch.Stop();
            Console.WriteLine(" {0} ms", stopwatch.ElapsedMilliseconds);
        }         // TimeGapCalculator
        public void CollectDaysTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(YearMonth.January);
            filter.WeekDays.Add(DayOfWeek.Friday);

            CalendarTimeRange testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            CalendarPeriodCollector collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectDays();

            Assert.AreEqual(collector.Periods.Count, 9);
            Assert.IsTrue(collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 01), new DateTime(2010, 1, 02))));
            Assert.IsTrue(collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 08), new DateTime(2010, 1, 09))));
            Assert.IsTrue(collector.Periods[2].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 15), new DateTime(2010, 1, 16))));
            Assert.IsTrue(collector.Periods[3].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 22), new DateTime(2010, 1, 23))));
            Assert.IsTrue(collector.Periods[4].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 29), new DateTime(2010, 1, 30))));
            Assert.IsTrue(collector.Periods[5].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 07), new DateTime(2011, 1, 08))));
            Assert.IsTrue(collector.Periods[6].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 14), new DateTime(2011, 1, 15))));
            Assert.IsTrue(collector.Periods[7].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 21), new DateTime(2011, 1, 22))));
            Assert.IsTrue(collector.Periods[8].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 28), new DateTime(2011, 1, 29))));
        }         // CollectDaysTest
Ejemplo n.º 25
0
        public void CalendarGetGapTest() {
            // simmulation of some reservations
            var periods = new TimePeriodCollection
                          {
                              new DayRangeCollection(2011, 3, 7, 2),
                              new DayRangeCollection(2011, 3, 16, 2)
                          };

            // the overall search range
            var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21));
            var days = new DayRangeCollection(limits.Start, limits.Duration.Days + 1);

            // limits의 내부이고, 주말인 DayRange를 추가합니다.
            var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd());
            periods.AddAll(excludeDays.Cast<ITimePeriod>());

            var gapCalculator = new TimeGapCalculator<TimeRange>(new TimeCalendar());
            var gaps = gapCalculator.GetGaps(periods, limits);

            gaps.Count.Should().Be(4);
            gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True();
            gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True();
            gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True();
            gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True();
        }
        public void CollectHoursTest() {
            //! 1월의 금요일의 8:00~18:00 까지 기간만을 계산한다.
            var filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(January);
            filter.WeekDays.Add(DayOfWeek.Friday);
            filter.CollectingHours.Add(new HourRangeInDay(8, 18));

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);
            collector.CollectHours();

            Assert.AreEqual(collector.Periods.Count, 9);
            Assert.IsTrue(
                collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 01, 8, 0, 0),
                                                                        new DateTime(2010, 1, 01, 18, 0, 0))),
                collector.Periods[0].ToString());
            Assert.IsTrue(
                collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 08, 8, 0, 0),
                                                                        new DateTime(2010, 1, 08, 18, 0, 0))),
                collector.Periods[1].ToString());
            Assert.IsTrue(
                collector.Periods[2].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 15, 8, 0, 0),
                                                                        new DateTime(2010, 1, 15, 18, 0, 0))),
                collector.Periods[2].ToString());
            Assert.IsTrue(
                collector.Periods[3].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 22, 8, 0, 0),
                                                                        new DateTime(2010, 1, 22, 18, 0, 0))),
                collector.Periods[3].ToString());
            Assert.IsTrue(
                collector.Periods[4].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 29, 8, 0, 0),
                                                                        new DateTime(2010, 1, 29, 18, 0, 0))),
                collector.Periods[4].ToString());
            Assert.IsTrue(
                collector.Periods[5].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 07, 8, 0, 0),
                                                                        new DateTime(2011, 1, 07, 18, 0, 0))),
                collector.Periods[5].ToString());
            Assert.IsTrue(
                collector.Periods[6].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 14, 8, 0, 0),
                                                                        new DateTime(2011, 1, 14, 18, 0, 0))),
                collector.Periods[6].ToString());
            Assert.IsTrue(
                collector.Periods[7].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 21, 8, 0, 0),
                                                                        new DateTime(2011, 1, 21, 18, 0, 0))),
                collector.Periods[7].ToString());
            Assert.IsTrue(
                collector.Periods[8].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 28, 8, 0, 0),
                                                                        new DateTime(2011, 1, 28, 18, 0, 0))),
                collector.Periods[8].ToString());
        }
Ejemplo n.º 27
0
        public override ITimePeriod GetTimePeriod(DateTime baseDate)
        {
            var startPoint = baseDate;
            CalendarTimeRange sequenceInterval = null;

            //Handle "every" as name/string value
            var retrievedEvery = EveryRetrieve.Match(Text).Value;

            if (retrievedEvery.Length > 0)
            {
                if (DateComponent.GetWeekDayFromName(retrievedEvery) != -1)
                {
                    startPoint       = DateComponent.GetNextDateFromWeekDay(retrievedEvery, baseDate);
                    sequenceInterval = new CalendarTimeRange(startPoint, new TimeSpan(7, 0, 0, 0));
                }
                else if (DateComponent.GetMonthFromName(retrievedEvery) != -1)
                {
                    startPoint       = DateComponent.GetNextDateFromMonth(retrievedEvery, baseDate);
                    sequenceInterval = new Months(startPoint, (YearMonth)startPoint.Month, 12);
                }
                else
                {
                    return(null);
                }
            }

            if (sequenceInterval == null)
            {
                var retrievedGenericSequence = GenericSequenceIntervalRetrieve.Match(Text).Value;
                var singularGenericSequence  = retrievedGenericSequence.TrimEnd('s').ToLower();

                //Handle "every" as numeric value
                var retrievedNumericInterval = NumericIntervalRetrieve.Match(Text).Value;
                var parsedNumericInterval    = 1;
                if (retrievedNumericInterval.Length > 0)
                {
                    parsedNumericInterval = int.Parse(retrievedNumericInterval);
                }

                TimeSpan duration;

                switch (singularGenericSequence)
                {
                case "minute":
                    duration         = new TimeSpan(0, parsedNumericInterval, 0);
                    sequenceInterval = new CalendarTimeRange(startPoint, duration);
                    break;

                case "hour":
                    duration         = new TimeSpan(parsedNumericInterval, 0, 0);
                    sequenceInterval = new CalendarTimeRange(startPoint, duration);
                    break;

                case "day":
                    duration         = new TimeSpan(parsedNumericInterval, 0, 0, 0);
                    sequenceInterval = new CalendarTimeRange(startPoint, duration);
                    break;

                case "week":
                    duration         = new TimeSpan(7 * parsedNumericInterval, 0, 0, 0);
                    sequenceInterval = new CalendarTimeRange(startPoint, duration);
                    break;

                case "month":
                    sequenceInterval = new Months(startPoint, (YearMonth)startPoint.Month, parsedNumericInterval);
                    break;

                case "year":
                    sequenceInterval = new Years(startPoint, parsedNumericInterval);
                    break;

                default:
                    return(null);
                }
            }

            var result = new SequencedTimeRange(sequenceInterval);

            return(result);
        }