public void SingleYearsTest() { const int startYear = 2004; Years years = new Years(startYear, 1); Assert.Equal(1, years.YearCount); Assert.Equal(years.StartYear, startYear); Assert.Equal(years.EndYear, startYear); Assert.Equal(1, years.GetYears().Count); Assert.True(years.GetYears()[0].IsSamePeriod(new Year(startYear))); } // SingleYearsTest
// ---------------------------------------------------------------------- public void YearStartSample() { TimeCalendar calendar = new TimeCalendar( new TimeCalendarConfig { YearBaseMonth = YearMonth.February }); Years years = new Years(2012, 2, calendar); // 2012-2013 Console.WriteLine("Quarters of Years (February): {0}", years); // > Quarters of Years (February): 2012 - 2014; 01.02.2012 - 31.01.2014 | 730.23:59 foreach (Year year in years.GetYears()) { foreach (Quarter quarter in year.GetQuarters()) { Console.WriteLine("Quarter: {0}", quarter); } } // > Quarter: Q1 2012; 01.02.2012 - 30.04.2012 | 89.23:59 // > Quarter: Q2 2012; 01.05.2012 - 31.07.2012 | 91.23:59 // > Quarter: Q3 2012; 01.08.2012 - 31.10.2012 | 91.23:59 // > Quarter: Q4 2012; 01.11.2012 - 31.01.2013 | 91.23:59 // > Quarter: Q1 2013; 01.02.2013 - 30.04.2013 | 88.23:59 // > Quarter: Q2 2013; 01.05.2013 - 31.07.2013 | 91.23:59 // > Quarter: Q3 2013; 01.08.2013 - 31.10.2013 | 91.23:59 // > Quarter: Q4 2013; 01.11.2013 - 31.01.2014 | 91.23:59 } // YearStartSample
// ---------------------------------------------------------------------- public static void ShowAll(int periodCount, int startYear, TimeCalendarConfig calendarConfig) { WriteLine("Input: count={0}, year={1}", periodCount, startYear); WriteLine("Calendar: base-month={0}, week-type={1}, culture={2}", calendarConfig.YearBaseMonth, calendarConfig.YearWeekType, calendarConfig.Culture.Name); WriteLine(); YearTimeRange yearTimeRange; if (periodCount == 1) { Year year = new Year(startYear, new TimeCalendar(calendarConfig)); yearTimeRange = year; Year previousYear = year.GetPreviousYear(); Year nextYears = year.GetNextYear(); ShowYear(year); ShowCompactYear(previousYear, "Previous Year"); ShowCompactYear(nextYears, "Next Year"); WriteLine(); } else { Years years = new Years(startYear, periodCount, new TimeCalendar(calendarConfig)); yearTimeRange = years; ShowYears(years); WriteLine(); foreach (Year year in years.GetYears()) { ShowCompactYear(year); } WriteLine(); } foreach (Halfyear halfyear in yearTimeRange.GetHalfyears()) { HalfyearDemo.ShowCompactHalfyear(halfyear); } WriteLine(); foreach (Quarter quarter in yearTimeRange.GetQuarters()) { QuarterDemo.ShowCompactQuarter(quarter); } WriteLine(); foreach (Month month in yearTimeRange.GetMonths()) { MonthDemo.ShowCompactMonth(month); } WriteLine(); } // ShowAll
public void DefaultCalendarYearsTest() { const int startYear = 2004; const int yearCount = 3; Years years = new Years(startYear, yearCount); Assert.Equal(years.YearCount, yearCount); Assert.Equal(years.StartYear, startYear); Assert.Equal(years.EndYear, startYear + yearCount - 1); int index = 0; foreach (Year year in years.GetYears()) { Assert.True(year.IsSamePeriod(new Year(startYear + index))); index++; } } // DefaultCalendarYearsTest
public void FiscalYearNearestDay() { ITimeCalendar calendar = new TimeCalendar(new TimeCalendarConfig { YearType = YearType.FiscalYear, YearBaseMonth = YearMonth.September, FiscalFirstDayOfYear = DayOfWeek.Sunday, FiscalYearAlignment = FiscalYearAlignment.NearestDay, FiscalQuarterGrouping = FiscalQuarterGrouping.FourFourFiveWeeks }); Years years = new Years(2005, 14, calendar); foreach (Year year in years.GetYears()) { Console.WriteLine("Fiscal year {0}: {1} - {2}", year.YearValue, year.Start.ToString("yyyy-MM-dd"), year.End.ToString("yyyy-MM-dd")); } } // FiscalYearNearestDay
public void CustomCalendarYearsTest() { const int startYear = 2004; const int yearCount = 3; const int startMonth = 4; Years years = new Years(startYear, yearCount, TimeCalendar.New((YearMonth)startMonth)); Assert.Equal(years.YearCount, yearCount); Assert.Equal(years.StartYear, startYear); Assert.Equal(years.EndYear, startYear + yearCount); int index = 0; foreach (Year year in years.GetYears()) { Assert.Equal(year.Start, new DateTime(startYear + index, startMonth, 1)); index++; } } // CustomCalendarYearsTest