public void GetMonthsTest() { const int startYear = 2004; const int yearCount = 10; const YearMonth startMonth = YearMonth.October; Years years = new Years(startYear, yearCount, TimeCalendar.New(startMonth)); ITimePeriodCollection months = years.GetMonths(); Assert.NotNull(months); int index = 0; foreach (Month month in months) { int monthYear; YearMonth monthMonth; TimeTool.AddMonth(startYear, startMonth, index, out monthYear, out monthMonth); Assert.Equal(month.Year, monthYear); Assert.Equal(month.Start, years.Start.AddMonths(index)); Assert.Equal(month.End, month.Calendar.MapEnd(month.Start.AddMonths(1))); index++; } Assert.Equal(index, yearCount * TimeSpec.MonthsPerYear); } // GetMonthsTest
public void CalendarHoursTest(int?monthCount) { var now = ClockProxy.Clock.Now; var months = new MonthRangeCollection(now, monthCount ?? 12); var startTime = now.TrimToDay().Add(months.TimeCalendar.StartOffset); var endTime = startTime.AddMonths(monthCount ?? 12).Add(months.TimeCalendar.EndOffset); months.Start.Should().Be(startTime); months.End.Should().Be(endTime); months.MonthCount.Should().Be(monthCount); var items = months.GetMonths().ToList(); items.Count.Should().Be(monthCount); Enumerable .Range(0, monthCount ?? 12) .RunEach(i => { items[i].Start.Should().Be(startTime.AddMonths(i)); items[i].End.Should().Be(months.TimeCalendar.MapEnd(startTime.AddMonths(i + 1))); items[i].UnmappedStart.Should().Be(startTime.AddMonths(i)); items[i].UnmappedEnd.Should().Be(startTime.AddMonths(i + 1)); items[i].IsSamePeriod(new MonthRange(months.Start.AddMonths(i))).Should().Be.True(); var ym = TimeTool.AddMonth(now.Year, now.Month, i); items[i].IsSamePeriod(new MonthRange(ym.Year ?? 0, ym.Month ?? 1)).Should().Be.True(); }); }
protected MonthTimeRange(int startYear, int startMonth, int monthCount, ITimeCalendar calendar) : base(GetPeriodOf(startYear, startMonth, monthCount), calendar) { monthCount.ShouldBePositive("monthCount"); MonthCount = monthCount; var yearAndMonth = TimeTool.AddMonth(startYear, startMonth, monthCount - 1); EndYear = yearAndMonth.Year ?? 0; EndMonth = yearAndMonth.Month ?? 1; }
public void GetMonthsTest() { const YearMonth startMonth = YearMonth.October; Year year = new Year(TimeCalendar.New(startMonth)); ITimePeriodCollection months = year.GetMonths(); Assert.AreNotEqual(months, null); int index = 0; foreach (Month month in months) { int monthYear; YearMonth monthMonth; TimeTool.AddMonth(year.YearValue, startMonth, index, out monthYear, out monthMonth); Assert.AreEqual(month.Year, monthYear); Assert.AreEqual(month.Start, year.Start.AddMonths(index)); Assert.AreEqual(month.End, month.Calendar.MapEnd(month.Start.AddMonths(1))); index++; } Assert.AreEqual(index, TimeSpec.MonthsPerYear); } // GetMonthsTest
public void AddMonthsTest() { int year; YearMonth month; TimeTool.AddMonth(YearMonth.January, 1, out year, out month); Assert.Equal(YearMonth.February, month); TimeTool.AddMonth(YearMonth.February, 1, out year, out month); Assert.Equal(YearMonth.March, month); TimeTool.AddMonth(YearMonth.March, 1, out year, out month); Assert.Equal(YearMonth.April, month); TimeTool.AddMonth(YearMonth.April, 1, out year, out month); Assert.Equal(YearMonth.May, month); TimeTool.AddMonth(YearMonth.May, 1, out year, out month); Assert.Equal(YearMonth.June, month); TimeTool.AddMonth(YearMonth.June, 1, out year, out month); Assert.Equal(YearMonth.July, month); TimeTool.AddMonth(YearMonth.July, 1, out year, out month); Assert.Equal(YearMonth.August, month); TimeTool.AddMonth(YearMonth.August, 1, out year, out month); Assert.Equal(YearMonth.September, month); TimeTool.AddMonth(YearMonth.September, 1, out year, out month); Assert.Equal(YearMonth.October, month); TimeTool.AddMonth(YearMonth.October, 1, out year, out month); Assert.Equal(YearMonth.November, month); TimeTool.AddMonth(YearMonth.November, 1, out year, out month); Assert.Equal(YearMonth.December, month); TimeTool.AddMonth(YearMonth.December, 1, out year, out month); Assert.Equal(YearMonth.January, month); TimeTool.AddMonth(YearMonth.January, -1, out year, out month); Assert.Equal(YearMonth.December, month); TimeTool.AddMonth(YearMonth.February, -1, out year, out month); Assert.Equal(YearMonth.January, month); TimeTool.AddMonth(YearMonth.March, -1, out year, out month); Assert.Equal(YearMonth.February, month); TimeTool.AddMonth(YearMonth.April, -1, out year, out month); Assert.Equal(YearMonth.March, month); TimeTool.AddMonth(YearMonth.May, -1, out year, out month); Assert.Equal(YearMonth.April, month); TimeTool.AddMonth(YearMonth.June, -1, out year, out month); Assert.Equal(YearMonth.May, month); TimeTool.AddMonth(YearMonth.July, -1, out year, out month); Assert.Equal(YearMonth.June, month); TimeTool.AddMonth(YearMonth.August, -1, out year, out month); Assert.Equal(YearMonth.July, month); TimeTool.AddMonth(YearMonth.September, -1, out year, out month); Assert.Equal(YearMonth.August, month); TimeTool.AddMonth(YearMonth.October, -1, out year, out month); Assert.Equal(YearMonth.September, month); TimeTool.AddMonth(YearMonth.November, -1, out year, out month); Assert.Equal(YearMonth.October, month); TimeTool.AddMonth(YearMonth.December, -1, out year, out month); Assert.Equal(YearMonth.November, month); for (int i = -36; i <= 36; i += 36) { TimeTool.AddMonth(YearMonth.January, i, out year, out month); Assert.Equal(YearMonth.January, month); TimeTool.AddMonth(YearMonth.February, i, out year, out month); Assert.Equal(YearMonth.February, month); TimeTool.AddMonth(YearMonth.March, i, out year, out month); Assert.Equal(YearMonth.March, month); TimeTool.AddMonth(YearMonth.April, i, out year, out month); Assert.Equal(YearMonth.April, month); TimeTool.AddMonth(YearMonth.May, i, out year, out month); Assert.Equal(YearMonth.May, month); TimeTool.AddMonth(YearMonth.June, i, out year, out month); Assert.Equal(YearMonth.June, month); TimeTool.AddMonth(YearMonth.July, i, out year, out month); Assert.Equal(YearMonth.July, month); TimeTool.AddMonth(YearMonth.August, i, out year, out month); Assert.Equal(YearMonth.August, month); TimeTool.AddMonth(YearMonth.September, i, out year, out month); Assert.Equal(YearMonth.September, month); TimeTool.AddMonth(YearMonth.October, i, out year, out month); Assert.Equal(YearMonth.October, month); TimeTool.AddMonth(YearMonth.November, i, out year, out month); Assert.Equal(YearMonth.November, month); TimeTool.AddMonth(YearMonth.December, i, out year, out month); Assert.Equal(YearMonth.December, month); } for (int i = 1; i < (3 * TimeSpec.MonthsPerYear); i++) { TimeTool.AddMonth(2008, (YearMonth)i, 1, out year, out month); Assert.Equal(year, 2008 + (i / 12)); Assert.Equal(month, (YearMonth)((i % TimeSpec.MonthsPerYear) + 1)); } } // AddMonthsTest