AddYears() public method

public AddYears ( int count ) : Year
count int
return Year
示例#1
0
        public void AddYearsTest()
        {
            Year currentYear = new Year( TimeCalendar.New( YearMonth.April ) );

            Assert.AreEqual( currentYear.AddYears( 0 ), currentYear );

            Year pastYear = currentYear.AddYears( -10 );
            Assert.AreEqual( pastYear.Start, currentYear.Start.AddYears( -10 ) );
            Assert.AreEqual( pastYear.End, currentYear.End.AddYears( -10 ) );

            Year futureYear = currentYear.AddYears( 10 );
            Assert.AreEqual( futureYear.Start, currentYear.Start.AddYears( 10 ) );
            Assert.AreEqual( futureYear.End, currentYear.End.AddYears( 10 ) );
        }
        // ----------------------------------------------------------------------
        private void SelectPeriod( PeriodSelectType periodSelectType )
        {
            int offset = 0;
            switch ( periodSelectType )
            {
                case PeriodSelectType.Previous:
                    offset = -1;
                    break;
                case PeriodSelectType.Current:
                    ResetWorkingPeriod();
                    return;
                case PeriodSelectType.Next:
                    offset = 1;
                    break;
            }

            switch ( WorkingTimePeriod )
            {
                case TimePeriodMode.Year:
                    Year year = new Year( WorkingPeriodStartDate );
                    SetWorkingPeriod( year.AddYears( offset ) );
                    break;
                case TimePeriodMode.Halfyear:
                    Halfyear halfyear = new Halfyear( WorkingPeriodStartDate );
                    SetWorkingPeriod( halfyear.AddHalfyears( offset ) );
                    break;
                case TimePeriodMode.Quarter:
                    Quarter quarter = new Quarter( WorkingPeriodStartDate );
                    SetWorkingPeriod( quarter.AddQuarters( offset ) );
                    break;
                case TimePeriodMode.Month:
                    Month month = new Month( WorkingPeriodStartDate );
                    SetWorkingPeriod( month.AddMonths( offset ) );
                    break;
                case TimePeriodMode.Week:
                    Week week = new Week( WorkingPeriodStartDate );
                    SetWorkingPeriod( week.AddWeeks( offset ) );
                    break;
                case TimePeriodMode.Day:
                    Day day = new Day( WorkingPeriodStartDate );
                    SetWorkingPeriod( day.AddDays( offset ) );
                    break;
            }
        }