AddHalfyears() public method

public AddHalfyears ( int count ) : Halfyear
count int
return Halfyear
Exemplo n.º 1
0
        public void AddHalfyearsTest()
        {
            int currentYear = ClockProxy.Clock.Now.Year;
            const YearMonth yearStartMonth = YearMonth.April;
            TimeCalendar calendar = TimeCalendar.New( TimeSpan.Zero, TimeSpan.Zero, yearStartMonth );

            DateTime calendarStartDate = new DateTime( currentYear, 4, 1 );
            Halfyear calendarHalfyear = new Halfyear( currentYear, YearHalfyear.First, calendar );

            Assert.AreEqual( calendarHalfyear.AddHalfyears( 0 ), calendarHalfyear );

            Halfyear prevH1 = calendarHalfyear.AddHalfyears( -1 );
            Assert.AreEqual( prevH1.YearHalfyear, YearHalfyear.Second );
            Assert.AreEqual( prevH1.BaseYear, currentYear - 1 );
            Assert.AreEqual( prevH1.Start, calendarStartDate.AddMonths( -6 ) );
            Assert.AreEqual( prevH1.End, calendarStartDate );

            Halfyear prevH2 = calendarHalfyear.AddHalfyears( -2 );
            Assert.AreEqual( prevH2.YearHalfyear, YearHalfyear.First );
            Assert.AreEqual( prevH2.BaseYear, currentYear - 1 );
            Assert.AreEqual( prevH2.Start, calendarStartDate.AddMonths( -12 ) );
            Assert.AreEqual( prevH2.End, calendarStartDate.AddMonths( -6 ) );

            Halfyear prevH3 = calendarHalfyear.AddHalfyears( -3 );
            Assert.AreEqual( prevH3.YearHalfyear, YearHalfyear.Second );
            Assert.AreEqual( prevH3.BaseYear, currentYear - 2 );
            Assert.AreEqual( prevH3.Start, calendarStartDate.AddMonths( -18 ) );
            Assert.AreEqual( prevH3.End, calendarStartDate.AddMonths( -12 ) );

            Halfyear futureH1 = calendarHalfyear.AddHalfyears( 1 );
            Assert.AreEqual( futureH1.YearHalfyear, YearHalfyear.Second );
            Assert.AreEqual( futureH1.BaseYear, currentYear );
            Assert.AreEqual( futureH1.Start, calendarStartDate.AddMonths( 6 ) );
            Assert.AreEqual( futureH1.End, calendarStartDate.AddMonths( 12 ) );

            Halfyear futureH2 = calendarHalfyear.AddHalfyears( 2 );
            Assert.AreEqual( futureH2.YearHalfyear, YearHalfyear.First );
            Assert.AreEqual( futureH2.BaseYear, currentYear + 1 );
            Assert.AreEqual( futureH2.Start, calendarStartDate.AddMonths( 12 ) );
            Assert.AreEqual( futureH2.End, calendarStartDate.AddMonths( 18 ) );

            Halfyear futureH3 = calendarHalfyear.AddHalfyears( 3 );
            Assert.AreEqual( futureH3.YearHalfyear, YearHalfyear.Second );
            Assert.AreEqual( futureH3.BaseYear, currentYear + 1 );
            Assert.AreEqual( futureH3.Start, calendarStartDate.AddMonths( 18 ) );
            Assert.AreEqual( futureH3.End, calendarStartDate.AddMonths( 24 ) );
        }
Exemplo n.º 2
0
        // ----------------------------------------------------------------------
        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;
            }
        }