Inheritance: HourTimeRange
Example #1
0
 // ----------------------------------------------------------------------
 public static void ShowHour( Hour hour, string caption = "Hour" )
 {
     WriteLine( "{0}: {1}", caption, hour );
     WriteIndentLine( "Year: {0}", hour.Year );
     WriteIndentLine( "Month: {0}", hour.Month );
     WriteIndentLine( "Day: {0}", hour.Day );
     WriteIndentLine( "HourValue: {0}", hour.HourValue );
     WriteIndentLine( "FirstMinuteStart: {0}", hour.FirstMinuteStart );
     WriteIndentLine( "LastMinuteStart: {0}", hour.LastMinuteStart );
     WriteLine();
 }
Example #2
0
 public void DefaultCalendarTest()
 {
     DateTime now = ClockProxy.Clock.Now;
     DateTime todayStart = new DateTime( now.Year, now.Month, now.Day );
     for ( int dayHour = 0; dayHour < TimeSpec.HoursPerDay; dayHour++ )
     {
         Hour hour = new Hour( todayStart.AddHours( dayHour ) );
         Assert.AreEqual( hour.Year, todayStart.Year );
         Assert.AreEqual( hour.Month, todayStart.Month );
         Assert.AreEqual( hour.Month, todayStart.Month );
         Assert.AreEqual( hour.Day, todayStart.Day );
         Assert.AreEqual( hour.HourValue, dayHour );
         Assert.AreEqual( hour.Start, todayStart.AddHours( dayHour ).Add( hour.Calendar.StartOffset ) );
         Assert.AreEqual( hour.End, todayStart.AddHours( dayHour + 1 ).Add( hour.Calendar.EndOffset ) );
     }
 }
        } // StartDayVisit

        // ----------------------------------------------------------------------
        protected Hour StartHourVisit(Hour hour, TContext context = null, SeekDirection?visitDirection = null)
        {
            if (hour == null)
            {
                throw new ArgumentNullException("hour");
            }

            if (visitDirection == null)
            {
                visitDirection = SeekDirection;
            }

            OnVisitStart();

            // iteration limits
            Hour     lastVisited = null;
            DateTime minStart    = DateTime.MinValue;
            DateTime maxEnd      = DateTime.MaxValue.AddHours(-1);

            while (hour.Start > minStart && hour.End < maxEnd)
            {
                if (OnVisitHour(hour, context) == false)
                {
                    lastVisited = hour;
                    break;
                }
                switch (visitDirection)
                {
                case SeekDirection.Forward:
                    hour = hour.GetNextHour();
                    break;

                case SeekDirection.Backward:
                    hour = hour.GetPreviousHour();
                    break;
                }
            }

            OnVisitEnd();

            return(lastVisited);
        } // StartHourVisit
Example #4
0
        public void AddHoursTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            DateTime nowHour = new DateTime( now.Year, now.Month, now.Day, now.Hour, 0, 0 );
            Hour hour = new Hour( now, TimeCalendar.New( TimeSpan.Zero, TimeSpan.Zero ) );

            Assert.AreEqual( hour.AddHours( 0 ), hour );

            DateTime previousHour = nowHour.AddHours( -1 );
            Assert.AreEqual( hour.AddHours( -1 ).Year, previousHour.Year );
            Assert.AreEqual( hour.AddHours( -1 ).Month, previousHour.Month );
            Assert.AreEqual( hour.AddHours( -1 ).Day, previousHour.Day );
            Assert.AreEqual( hour.AddHours( -1 ).HourValue, previousHour.Hour );

            DateTime nextHour = nowHour.AddHours( 1 );
            Assert.AreEqual( hour.AddHours( 1 ).Year, nextHour.Year );
            Assert.AreEqual( hour.AddHours( 1 ).Month, nextHour.Month );
            Assert.AreEqual( hour.AddHours( 1 ).Day, nextHour.Day );
            Assert.AreEqual( hour.AddHours( 1 ).HourValue, nextHour.Hour );
        }
Example #5
0
        // ----------------------------------------------------------------------
        public static void ShowAll( int periodCount, int year, YearMonth month, int day, int hourValue )
        {
            WriteLine( "Input: count={0}, year={1}, month={2}, day={3}, hour={4}", periodCount, year, month, day, hourValue );
            WriteLine();

            HourTimeRange hourTimeRange;
            if ( periodCount == 1 )
            {
                Hour hour = new Hour( year, (int)month, day, hourValue );
                hourTimeRange = hour;

                Hour previousHour = hour.GetPreviousHour();
                Hour nextHour = hour.GetNextHour();

                ShowHour( hour );
                ShowCompactHour( previousHour, "Previous Hour" );
                ShowCompactHour( nextHour, "Next Hour" );
                WriteLine();
            }
            else
            {
                Hours hours = new Hours( year, (int)month, day, hourValue, periodCount );
                hourTimeRange = hours;

                ShowHours( hours );
                WriteLine();

                foreach ( Hour hour in hours.GetHours() )
                {
                    ShowCompactHour( hour );
                }
                WriteLine();
            }

            foreach ( Minute minute in hourTimeRange.GetMinutes() )
            {
                MinuteDemo.ShowCompactMinute( minute );
            }
            WriteLine();
        }
Example #6
0
        public void GetMinutesTest()
        {
            Hour hour = new Hour();

            ITimePeriodCollection minutes = hour.GetMinutes();
            Assert.AreNotEqual( minutes, null );

            int index = 0;
            foreach ( Minute minute in minutes )
            {
                Assert.AreEqual( minute.Start, hour.Start.AddMinutes( index ) );
                Assert.AreEqual( minute.End, minute.Calendar.MapEnd( minute.Start.AddMinutes( 1 ) ) );
                index++;
            }
            Assert.AreEqual( index, TimeSpec.MinutesPerHour );
        }
Example #7
0
        public void InitValuesTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            DateTime firstHour = new DateTime( now.Year, now.Month, now.Day, now.Hour, 0, 0 );
            DateTime secondHour = firstHour.AddHours( 1 );
            Hour hour = new Hour( now, TimeCalendar.NewEmptyOffset() );

            Assert.AreEqual( hour.Start.Year, firstHour.Year );
            Assert.AreEqual( hour.Start.Month, firstHour.Month );
            Assert.AreEqual( hour.Start.Day, firstHour.Day );
            Assert.AreEqual( hour.Start.Hour, firstHour.Hour );
            Assert.AreEqual( hour.Start.Minute, 0 );
            Assert.AreEqual( hour.Start.Second, 0 );
            Assert.AreEqual( hour.Start.Millisecond, 0 );

            Assert.AreEqual( hour.End.Year, secondHour.Year );
            Assert.AreEqual( hour.End.Month, secondHour.Month );
            Assert.AreEqual( hour.End.Day, secondHour.Day );
            Assert.AreEqual( hour.End.Hour, secondHour.Hour );
            Assert.AreEqual( hour.End.Minute, 0 );
            Assert.AreEqual( hour.End.Second, 0 );
            Assert.AreEqual( hour.End.Millisecond, 0 );
        }
Example #8
0
 public void GetPreviousHourTest()
 {
     Hour hour = new Hour();
     Assert.AreEqual( hour.GetPreviousHour(), hour.AddHours( -1 ) );
 }
Example #9
0
 public void GetNextHourTest()
 {
     Hour hour = new Hour();
     Assert.AreEqual( hour.GetNextHour(), hour.AddHours( 1 ) );
 }
Example #10
0
 // ----------------------------------------------------------------------
 private void UpdateSelectedPeriodInfo()
 {
     TimeCalendar timeCalendar = TimeCalendar.New( SelectedYearBaseMonth );
     switch ( SelectedPeriodMode )
     {
         case TimePeriodMode.Year:
             Year year = new Year( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Year", year );
             periodInfo.AddItem( "YearBaseMonth", year.YearBaseMonth );
             periodInfo.AddItem( "IsCalendarYear", year.IsCalendarYear );
             periodInfo.AddItem( "StartYear", year.StartYear );
             periodInfo.AddItem( "FirstDayStart", year.FirstDayStart );
             periodInfo.AddItem( "LastDayStart", year.LastDayStart );
             periodInfo.AddItem( "LastMonthStart", year.LastMonthStart );
             periodInfo.AddItem( "YearName", year.YearName );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", year.GetPreviousYear() );
             periodInfo.AddItem( "Next", year.GetNextYear() );
             periodInfo.AddSubitems( "Halfyears", year.GetHalfyears() );
             periodInfo.AddSubitems( "Quarters", year.GetQuarters() );
             periodInfo.AddSubitems( "Months", year.GetMonths() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Halfyear:
             Halfyear halfyear = new Halfyear( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Halfyear", halfyear );
             periodInfo.AddItem( "YearBaseMonth", halfyear.YearBaseMonth );
             periodInfo.AddItem( "StartMonth", halfyear.StartMonth );
             periodInfo.AddItem( "Year", halfyear.Year );
             periodInfo.AddItem( "YearHalfyear", halfyear.YearHalfyear );
             periodInfo.AddItem( "IsCalendarHalfyear", halfyear.IsCalendarHalfyear );
             periodInfo.AddItem( "MultipleCalendarYears", halfyear.MultipleCalendarYears );
             periodInfo.AddItem( "HalfyearName", halfyear.HalfyearName );
             periodInfo.AddItem( "HalfyearOfYearName", halfyear.HalfyearOfYearName );
             periodInfo.AddItem( "LastDayStart", halfyear.LastDayStart );
             periodInfo.AddItem( "LastMonthStart", halfyear.LastMonthStart );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previousr", halfyear.GetPreviousHalfyear() );
             periodInfo.AddItem( "Next", halfyear.GetNextHalfyear() );
             periodInfo.AddSubitems( "Quarters", halfyear.GetQuarters() );
             periodInfo.AddSubitems( "Months", halfyear.GetMonths() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Quarter:
             Quarter quarter = new Quarter( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Quarter", quarter );
             periodInfo.AddItem( "YearBaseMonth", quarter.YearBaseMonth );
             periodInfo.AddItem( "StartMonth", quarter.StartMonth );
             periodInfo.AddItem( "Year", quarter.Year );
             periodInfo.AddItem( "YearQuarter", quarter.YearQuarter );
             periodInfo.AddItem( "IsCalendarQuarter", quarter.IsCalendarQuarter );
             periodInfo.AddItem( "MultipleCalendarYears", quarter.MultipleCalendarYears );
             periodInfo.AddItem( "QuarterName", quarter.QuarterName );
             periodInfo.AddItem( "QuarterOfYearName", quarter.QuarterOfYearName );
             periodInfo.AddItem( "LastDayStart", quarter.FirstDayStart );
             periodInfo.AddItem( "LastMonthStart", quarter.LastDayStart );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", quarter.GetPreviousQuarter() );
             periodInfo.AddItem( "Next", quarter.GetNextQuarter() );
             periodInfo.AddSubitems( "Months", quarter.GetMonths() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Month:
             Month month = new Month( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Month", month );
             periodInfo.AddItem( "YearBaseMonth", month.YearMonth );
             periodInfo.AddItem( "Year", month.Year );
             periodInfo.AddItem( "DaysInMonth", month.DaysInMonth );
             periodInfo.AddItem( "MonthName", month.MonthName );
             periodInfo.AddItem( "MonthOfYearName", month.MonthOfYearName );
             periodInfo.AddItem( "LastDayStart", month.FirstDayStart );
             periodInfo.AddItem( "LastMonthStart", month.LastDayStart );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", month.GetPreviousMonth() );
             periodInfo.AddItem( "Next", month.GetNextMonth() );
             periodInfo.AddSubitems( "Days", month.GetDays() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Week:
             Week week = new Week( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Week", week );
             periodInfo.AddItem( "MultipleCalendarYears", week.MultipleCalendarYears );
             periodInfo.AddItem( "FirstDayStart", week.FirstDayStart );
             periodInfo.AddItem( "FirstDayOfWeek", week.FirstDayOfWeek );
             periodInfo.AddItem( "LastDayStart", week.LastDayStart );
             periodInfo.AddItem( "LastDayOfWeek", week.LastDayOfWeek );
             periodInfo.AddItem( "WeekOfYear", week.WeekOfYear );
             periodInfo.AddItem( "WeekOfYearName", week.WeekOfYearName );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", week.GetPreviousWeek() );
             periodInfo.AddItem( "Next", week.GetNextWeek() );
             periodInfo.AddSubitems( "Days", week.GetDays() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Day:
             Day day = new Day( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Day", day );
             periodInfo.AddItem( "Year", day.Year );
             periodInfo.AddItem( "FirstDayStart", day.FirstDayStart );
             periodInfo.AddItem( "Month", day.Month );
             periodInfo.AddItem( "DayValue", day.DayValue );
             periodInfo.AddItem( "DayOfWeek", day.DayOfWeek );
             periodInfo.AddItem( "DayName", day.DayName );
             periodInfo.AddItem( "FirstHourStart", day.FirstHourStart );
             periodInfo.AddItem( "LastHourStart", day.LastHourStart );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", day.GetPreviousDay() );
             periodInfo.AddItem( "Next", day.GetNextDay() );
             periodInfo.AddSubitems( "Hours", day.GetHours() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Hour:
             Hour hour = new Hour( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Hour", hour );
             periodInfo.AddItem( "Year", hour.Year );
             periodInfo.AddItem( "Month", hour.Month );
             periodInfo.AddItem( "Day", hour.Day );
             periodInfo.AddItem( "HourValue", hour.HourValue );
             periodInfo.AddItem( "FirstMinuteStart", hour.FirstMinuteStart );
             periodInfo.AddItem( "LastMinuteStart", hour.LastMinuteStart );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", hour.GetPreviousHour() );
             periodInfo.AddItem( "Next", hour.GetNextHour() );
             periodInfo.AddSubitems( "Minutes", hour.GetMinutes() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
         case TimePeriodMode.Minute:
             Minute minute = new Minute( WorkingDate, timeCalendar );
             periodInfo.Clear();
             periodInfo.AddItem( "Minute", minute );
             periodInfo.AddItem( "Year", minute.Year );
             periodInfo.AddItem( "Month", minute.Month );
             periodInfo.AddItem( "Day", minute.Day );
             periodInfo.AddItem( "Hour", minute.Hour );
             periodInfo.AddItem( "MinuteValue", minute.MinuteValue );
             periodInfo.AddSection( "Previous/Next" );
             periodInfo.AddItem( "Previous", minute.GetPreviousMinute() );
             periodInfo.AddItem( "Next", minute.GetNextMinute() );
             SelectedPeriodInfo = periodInfo.ToString();
             break;
     }
 }
        } // OnVisitDay

        // ----------------------------------------------------------------------
        protected virtual bool OnVisitHour(Hour hour, TContext context)
        {
            return(true);
        } // OnVisitHour
Example #12
0
 // ----------------------------------------------------------------------
 public static void ShowCompactHour( Hour hour, string caption = "Hour" )
 {
     WriteLine( "{0}: {1}", caption, hour );
 }