public CalendarMonth GetCalendarMonth(int year, int month) { // Get first day of month var firstDayOfMonthResult = GetFirstDayOfMonth(year, month); if (firstDayOfMonthResult == null) { return(null); } // Get first day of week for current week var firstDayOfMonth = firstDayOfMonthResult.Value; var firstDayOfWeekMonth = firstDayOfMonth; while (firstDayOfWeekMonth.DayOfWeek != CalendarWeek.FirstDayOfWeek) { firstDayOfWeekMonth = firstDayOfWeekMonth.AddDays(-1); } // Fill calendar var calendarMonth = new CalendarMonth(); var currentCalendarDate = firstDayOfWeekMonth; var firstDayOfCurrentWeek = firstDayOfWeekMonth; var firstDayOfNextMonth = firstDayOfMonth.AddMonths(1); while (firstDayOfCurrentWeek < firstDayOfNextMonth) { var calendarWeek = new CalendarWeek(); foreach (var weekDay in CalendarWeek.WeekDays) { var calendarDay = new CalendarDay(); calendarDay.Type = GetCalendarDayType(currentCalendarDate, month); calendarDay.Value = GetCalendarDayValue(currentCalendarDate); calendarWeek[weekDay] = calendarDay; currentCalendarDate = currentCalendarDate.AddDays(1); } calendarMonth.Weeks.Add(calendarWeek); firstDayOfCurrentWeek = currentCalendarDate; } calendarMonth.Year = year; calendarMonth.MonthName = GetMonthName(month); return(calendarMonth); }
public CalendarWeek() { values = new CalendarDay[7]; }