Example #1
0
        public void GetHalfyearsTest()
        {
            Year year = new Year( TimeCalendar.New( YearMonth.October ) );

            ITimePeriodCollection halfyears = year.GetHalfyears();
            Assert.AreNotEqual( halfyears, null );

            int index = 0;
            foreach ( Halfyear halfyear in halfyears )
            {
                Assert.AreEqual( halfyear.BaseYear, year.BaseYear );
                Assert.AreEqual( halfyear.Start, year.Start.AddMonths( index * TimeSpec.MonthsPerHalfyear ) );
                Assert.AreEqual( halfyear.End, halfyear.Calendar.MapEnd( halfyear.Start.AddMonths( TimeSpec.MonthsPerHalfyear ) ) );
                index++;
            }
            Assert.AreEqual( index, TimeSpec.HalfyearsPerYear );
        }
Example #2
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;
     }
 }
Example #3
0
        public void FiscalYearTest()
        {
            DateTime testDate = new DateTime( 2008, 11, 18 );
            Year year = new Year( testDate, TimeCalendar.New( YearMonth.October ) );

            Assert.AreEqual( year.YearBaseMonth, YearMonth.October );
            Assert.AreEqual( year.BaseYear, 2008 );

            // start & end
            Assert.AreEqual( year.Start.Year, testDate.Year );
            Assert.AreEqual( year.Start.Month, 10 );
            Assert.AreEqual( year.Start.Day, 1 );
            Assert.AreEqual( year.End.Year, testDate.Year + 1 );
            Assert.AreEqual( year.End.Month, 9 );
            Assert.AreEqual( year.End.Day, 30 );

            // half years
            ITimePeriodCollection halfyears = year.GetHalfyears();
            foreach ( Halfyear halfyear in halfyears )
            {
                switch ( halfyear.YearHalfyear )
                {
                    case YearHalfyear.First:
                        Assert.AreEqual( halfyear.Start, year.Start );
                        Assert.AreEqual( halfyear.Start.Year, testDate.Year );
                        Assert.AreEqual( halfyear.Start.Month, 10 );
                        Assert.AreEqual( halfyear.Start.Day, 1 );
                        Assert.AreEqual( halfyear.End.Year, testDate.Year + 1 );
                        Assert.AreEqual( halfyear.End.Month, 3 );
                        Assert.AreEqual( halfyear.End.Day, 31 );
                        break;
                    case YearHalfyear.Second:
                        Assert.AreEqual( halfyear.End, year.End );
                        Assert.AreEqual( halfyear.Start.Year, testDate.Year + 1 );
                        Assert.AreEqual( halfyear.Start.Month, 4 );
                        Assert.AreEqual( halfyear.Start.Day, 1 );
                        Assert.AreEqual( halfyear.End.Year, testDate.Year + 1 );
                        Assert.AreEqual( halfyear.End.Month, 9 );
                        Assert.AreEqual( halfyear.End.Day, 30 );
                        break;
                }
            }

            // half years
            ITimePeriodCollection quarters = year.GetQuarters();
            foreach ( Quarter quarter in quarters )
            {
                switch ( quarter.YearQuarter )
                {
                    case YearQuarter.First:
                        Assert.AreEqual( quarter.Start, year.Start );
                        Assert.AreEqual( quarter.Start.Year, testDate.Year );
                        Assert.AreEqual( quarter.Start.Month, 10 );
                        Assert.AreEqual( quarter.Start.Day, 1 );
                        Assert.AreEqual( quarter.End.Year, testDate.Year );
                        Assert.AreEqual( quarter.End.Month, 12 );
                        Assert.AreEqual( quarter.End.Day, 31 );
                        break;
                    case YearQuarter.Second:
                        Assert.AreEqual( quarter.Start.Year, testDate.Year + 1 );
                        Assert.AreEqual( quarter.Start.Month, 1 );
                        Assert.AreEqual( quarter.Start.Day, 1 );
                        Assert.AreEqual( quarter.End.Year, testDate.Year + 1 );
                        Assert.AreEqual( quarter.End.Month, 3 );
                        Assert.AreEqual( quarter.End.Day, 31 );
                        break;
                    case YearQuarter.Third:
                        Assert.AreEqual( quarter.Start.Year, testDate.Year + 1 );
                        Assert.AreEqual( quarter.Start.Month, 4 );
                        Assert.AreEqual( quarter.Start.Day, 1 );
                        Assert.AreEqual( quarter.End.Year, testDate.Year + 1 );
                        Assert.AreEqual( quarter.End.Month, 6 );
                        Assert.AreEqual( quarter.End.Day, 30 );
                        break;
                    case YearQuarter.Fourth:
                        Assert.AreEqual( quarter.End, year.End );
                        Assert.AreEqual( quarter.Start.Year, testDate.Year + 1 );
                        Assert.AreEqual( quarter.Start.Month, 7 );
                        Assert.AreEqual( quarter.Start.Day, 1 );
                        Assert.AreEqual( quarter.End.Year, testDate.Year + 1 );
                        Assert.AreEqual( quarter.End.Month, 9 );
                        Assert.AreEqual( quarter.End.Day, 30 );
                        break;
                }
            }

            // months
            ITimePeriodCollection months = year.GetMonths();
            int monthIndex = 0;
            foreach ( Month month in months )
            {
                switch ( monthIndex )
                {
                    case 0:
                        Assert.AreEqual( month.Start, year.Start );
                        break;
                    case TimeSpec.MonthsPerYear - 1:
                        Assert.AreEqual( month.End, year.End );
                        break;
                }

                DateTime startDate = new DateTime( year.BaseYear, year.Start.Month, 1 ).AddMonths( monthIndex );
                Assert.AreEqual( month.Start.Year, startDate.Year );
                Assert.AreEqual( month.Start.Month, startDate.Month );
                Assert.AreEqual( month.Start.Day, startDate.Day );
                Assert.AreEqual( month.End.Year, startDate.Year );
                Assert.AreEqual( month.End.Month, startDate.Month );

                monthIndex++;
            }
        }