GetDays() public method

public GetDays ( ) : ITimePeriodCollection
return ITimePeriodCollection
        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.AreEqual( gaps.Count, 4 );
            Assert.IsTrue( gaps[ 0 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 4 ), Duration.Days( 1 ) ) ) );
            Assert.IsTrue( gaps[ 1 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 9 ), Duration.Days( 3 ) ) ) );
            Assert.IsTrue( gaps[ 2 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 14 ), Duration.Days( 2 ) ) ) );
            Assert.IsTrue( gaps[ 3 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 18 ), Duration.Days( 1 ) ) ) );
        }
Esempio n. 2
0
        public void SingleDaysTest()
        {
            const int startYear = 2004;
            const int startMonth = 2;
            const int startDay = 22;
            Days days = new Days( startYear, startMonth, startDay, 1 );

            Assert.AreEqual( days.DayCount, 1 );
            Assert.AreEqual( days.StartYear, startYear );
            Assert.AreEqual( days.StartMonth, startMonth );
            Assert.AreEqual( days.StartDay, startDay );
            Assert.AreEqual( days.EndYear, 2004 );
            Assert.AreEqual( days.EndMonth, 2 );
            Assert.AreEqual( days.EndDay, startDay );
            Assert.AreEqual( days.GetDays().Count, 1 );
            Assert.IsTrue( days.GetDays()[ 0 ].IsSamePeriod( new Day( 2004, 2, 22 ) ) );
        }
        }                  // OnVisitYear

        // ----------------------------------------------------------------------
        protected override bool OnVisitMonth(Month month, CalendarPeriodCollectorContext context)
        {
            if (context.Scope != CalendarPeriodCollectorContext.CollectType.Day)
            {
                return(true);                // continue
            }

            if (Filter.CollectingDays.Count == 0)
            {
                foreach (Day day in month.GetDays())
                {
                    if (IsMatchingDay(day, context) && CheckLimits(day))
                    {
                        periods.Add(day);
                    }
                }
            }
            else             // custom days
            {
                foreach (DayRange collectingDay in Filter.CollectingDays)
                {
                    if (collectingDay.IsSingleDay)
                    {
                        Day day = new Day(month.Year, month.MonthValue, collectingDay.Min, month.Calendar);
                        if (IsMatchingDay(day, context) && CheckLimits(day))
                        {
                            periods.Add(day);
                        }
                    }
                    else
                    {
                        Days days       = new Days(month.Year, month.MonthValue, collectingDay.Min, collectingDay.Max - collectingDay.Min, month.Calendar);
                        bool isMatching = true;
                        foreach (Day day in days.GetDays())
                        {
                            if (IsMatchingDay(day, context))
                            {
                                continue;
                            }
                            isMatching = false;
                            break;
                        }
                        if (isMatching && CheckLimits(days))
                        {
                            periods.Add(days);
                        }
                    }
                }
            }

            return(false); // abort
        }                  // OnVisitMonth
Esempio n. 4
0
        // ----------------------------------------------------------------------
        public static void ShowAll( int periodCount, int year, YearMonth yearMonth, int dayValue )
        {
            WriteLine( "Input: count={0}, year={1}, month={2}, day={3}", periodCount, year, yearMonth, dayValue );
            WriteLine();

            DayTimeRange dayTimeRange;
            if ( periodCount == 1 )
            {
                Day day = new Day( year, (int)yearMonth, dayValue );
                dayTimeRange = day;

                Day previousDay = day.GetPreviousDay();
                Day nextDay = day.GetNextDay();

                ShowDay( day );
                ShowCompactDay( previousDay, "Previous Day" );
                ShowCompactDay( nextDay, "Next Day" );
                WriteLine();
            }
            else
            {
                Days days = new Days( year, (int)yearMonth, dayValue, periodCount );
                dayTimeRange = days;

                ShowDays( days );
                WriteLine();

                foreach ( Day day in days.GetDays() )
                {
                    ShowCompactDay( day );
                }
                WriteLine();
            }

            foreach ( Hour hour in dayTimeRange.GetHours() )
            {
                HourDemo.ShowCompactHour( hour );
            }
            WriteLine();
        }
Esempio n. 5
0
        public void CalendarDaysTest()
        {
            const int startYear = 2004;
            const int startMonth = 2;
            const int startDay = 27;
            const int dayCount = 5;
            Days days = new Days( startYear, startMonth, startDay, dayCount );

            Assert.AreEqual( days.DayCount, dayCount );
            Assert.AreEqual( days.StartYear, startYear );
            Assert.AreEqual( days.StartMonth, startMonth );
            Assert.AreEqual( days.StartDay, startDay );
            Assert.AreEqual( days.EndYear, 2004 );
            Assert.AreEqual( days.EndMonth, 3 );
            Assert.AreEqual( days.EndDay, 2 );
            Assert.AreEqual( days.GetDays().Count, dayCount );
            Assert.IsTrue( days.GetDays()[ 0 ].IsSamePeriod( new Day( 2004, 2, 27 ) ) );
            Assert.IsTrue( days.GetDays()[ 1 ].IsSamePeriod( new Day( 2004, 2, 28 ) ) );
            Assert.IsTrue( days.GetDays()[ 2 ].IsSamePeriod( new Day( 2004, 2, 29 ) ) );
            Assert.IsTrue( days.GetDays()[ 3 ].IsSamePeriod( new Day( 2004, 3, 1 ) ) );
            Assert.IsTrue( days.GetDays()[ 4 ].IsSamePeriod( new Day( 2004, 3, 2 ) ) );
        }