GetMonths() public method

public GetMonths ( ) : ITimePeriodCollection
return ITimePeriodCollection
Beispiel #1
0
        public void SingleMonthsTest()
        {
            const int startYear = 2004;
            const YearMonth startMonth = YearMonth.June;
            Months months = new Months( startYear, startMonth, 1 );

            Assert.AreEqual( months.MonthCount, 1 );
            Assert.AreEqual( months.StartMonth, startMonth );
            Assert.AreEqual( months.StartYear, startYear );
            Assert.AreEqual( months.EndYear, startYear );
            Assert.AreEqual( months.EndMonth, YearMonth.June );
            Assert.AreEqual( months.GetMonths().Count, 1 );
            Assert.IsTrue( months.GetMonths()[ 0 ].IsSamePeriod( new Month( 2004, YearMonth.June ) ) );
        }
        }                  // OnVisitYears

        // ----------------------------------------------------------------------
        protected override bool OnVisitYear(Year year, CalendarPeriodCollectorContext context)
        {
            if (context.Scope != CalendarPeriodCollectorContext.CollectType.Month)
            {
                return(true);                // continue
            }

            // all months
            if (Filter.CollectingMonths.Count == 0)
            {
                foreach (Month month in year.GetMonths())
                {
                    if (IsMatchingMonth(month, context) && CheckLimits(month))
                    {
                        periods.Add(month);
                    }
                }
            }
            else             // custom months
            {
                foreach (MonthRange collectingMonth in Filter.CollectingMonths)
                {
                    if (collectingMonth.IsSingleMonth)
                    {
                        Month month = new Month(year.YearValue, collectingMonth.Min, year.Calendar);
                        if (IsMatchingMonth(month, context) && CheckLimits(month))
                        {
                            periods.Add(month);
                        }
                    }
                    else
                    {
                        Months months = new Months(year.YearValue, collectingMonth.Min,
                                                   collectingMonth.Max - collectingMonth.Min, year.Calendar);
                        bool isMatching = true;
                        foreach (Month month in months.GetMonths())
                        {
                            if (IsMatchingMonth(month, context))
                            {
                                continue;
                            }
                            isMatching = false;
                            break;
                        }
                        if (isMatching && CheckLimits(months))
                        {
                            periods.Add(months);
                        }
                    }
                }
            }

            return(false); // abort
        }                  // OnVisitYear
Beispiel #3
0
        // ----------------------------------------------------------------------
        public static void ShowAll( int periodCount, int year, YearMonth yearMonth )
        {
            WriteLine( "Input: count={0}, year={1}, month={2}", periodCount, year, yearMonth );
            WriteLine();

            MonthTimeRange monthTimeRange;
            if ( periodCount == 1 )
            {
                Month month = new Month( year, yearMonth );
                monthTimeRange = month;

                Month previousMonth = month.GetPreviousMonth();
                Month nextMonth = month.GetNextMonth();

                ShowMonth( month );
                ShowCompactMonth( previousMonth, "Previous Month" );
                ShowCompactMonth( nextMonth, "Next Month" );
                WriteLine();
            }
            else
            {
                Months months = new Months( year, yearMonth, periodCount );
                monthTimeRange = months;

                ShowMonths( months );
                WriteLine();

                foreach ( Month month in months.GetMonths() )
                {
                    ShowCompactMonth( month );
                }
                WriteLine();
            }

            foreach ( Day day in monthTimeRange.GetDays() )
            {
                DayDemo.ShowCompactDay( day );
            }
            WriteLine();
        }
Beispiel #4
0
        public void CalendarMonthsTest()
        {
            const int startYear = 2004;
            const YearMonth startMonth = YearMonth.November;
            const int monthCount = 5;
            Months months = new Months( startYear, startMonth, monthCount );

            Assert.AreEqual( months.MonthCount, monthCount );
            Assert.AreEqual( months.StartMonth, startMonth );
            Assert.AreEqual( months.StartYear, startYear );
            Assert.AreEqual( months.EndYear, 2005 );
            Assert.AreEqual( months.EndMonth, YearMonth.March );
            Assert.AreEqual( months.GetMonths().Count, monthCount );
            Assert.IsTrue( months.GetMonths()[ 0 ].IsSamePeriod( new Month( 2004, YearMonth.November ) ) );
            Assert.IsTrue( months.GetMonths()[ 1 ].IsSamePeriod( new Month( 2004, YearMonth.December ) ) );
            Assert.IsTrue( months.GetMonths()[ 2 ].IsSamePeriod( new Month( 2005, YearMonth.January ) ) );
            Assert.IsTrue( months.GetMonths()[ 3 ].IsSamePeriod( new Month( 2005, YearMonth.February ) ) );
            Assert.IsTrue( months.GetMonths()[ 4 ].IsSamePeriod( new Month( 2005, YearMonth.March ) ) );
        }