Наследование: DayTimeRange
Пример #1
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.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 ) ) ) );
        }
Пример #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 ) ) );
        }
Пример #3
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();
        }
Пример #4
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 ) ) );
        }
Пример #5
0
 // ----------------------------------------------------------------------
 public static void ShowDays( Days days, string caption = "Days" )
 {
     WriteLine( "{0}: {1}", caption, days );
     WriteIndentLine( "StartYear: {0}", days.StartYear );
     WriteIndentLine( "StartMonth: {0}", days.StartMonth );
     WriteIndentLine( "StartDay: {0}", days.StartDay );
     WriteIndentLine( "EndYear: {0}", days.EndYear );
     WriteIndentLine( "EndMonth: {0}", days.EndMonth );
     WriteIndentLine( "EndDay: {0}", days.EndDay );
     WriteIndentLine( "FirstDayStart: {0}", Format( days.FirstDayStart ) );
     WriteIndentLine( "LastDayStart: {0}", Format( days.LastDayStart ) );
     WriteIndentLine( "FirstHourStart: {0}", days.FirstHourStart );
     WriteIndentLine( "LastHourStart: {0}", days.LastHourStart );
     WriteLine();
 }
Пример #6
0
 // ----------------------------------------------------------------------
 public static void ShowCompactDays( Days days, string caption = "Days" )
 {
     WriteLine( "{0}: {1}", caption, days );
 }