internal DateTime GetFirstDateToRenderForDisplayMode(DateTime date, CalendarDisplayMode displayMode) { date = date.Date; DateTime firstDateToRender = date; if (displayMode == CalendarDisplayMode.MultiDayView) { DayOfWeek firstDayOfWeek = this.GetFirstDayOfWeek(); DateTime firstDateOfCurrentWeek = CalendarMathHelper.GetFirstDayOfCurrentWeek(date, firstDayOfWeek); if (!(firstDateOfCurrentWeek.Date <= date.Date && firstDateOfCurrentWeek.AddDays(7).Date >= date.Date)) { firstDateToRender = firstDateOfCurrentWeek; } if (!this.multiDayViewSettings.WeekendsVisible) { firstDateToRender = CalendarMathHelper.AddBusinessDays(date, -this.multiDayViewSettings.VisibleDays); } else { firstDateToRender = date.AddDays(-this.multiDayViewSettings.VisibleDays); } } else if (displayMode == CalendarDisplayMode.MonthView) { DayOfWeek firstDayOfWeekToUse = this.GetFirstDayOfWeek(); DateTime monthStartDate = CalendarMathHelper.GetFirstDateOfMonth(date); int daysToSubtract = (int)monthStartDate.DayOfWeek - (int)firstDayOfWeekToUse; if (daysToSubtract <= 0) { daysToSubtract += 7; } firstDateToRender = monthStartDate.Date == DateTime.MinValue.Date ? monthStartDate : monthStartDate.AddDays(-daysToSubtract); } else if (displayMode == CalendarDisplayMode.YearView) { firstDateToRender = CalendarMathHelper.GetFirstDateOfYear(date); } else if (displayMode == CalendarDisplayMode.DecadeView) { firstDateToRender = CalendarMathHelper.GetFirstDateOfDecade(date); } else if (displayMode == CalendarDisplayMode.CenturyView) { firstDateToRender = CalendarMathHelper.GetFirstDateOfCentury(date); } return(firstDateToRender); }
internal override DateTime GetFirstDateToRender(DateTime date) { DayOfWeek firstDayOfWeekToUse = this.Calendar.GetFirstDayOfWeek(); DateTime monthStartDate = CalendarMathHelper.GetFirstDateOfMonth(date); int daysToSubtract = (int)monthStartDate.DayOfWeek - (int)firstDayOfWeekToUse; if (daysToSubtract <= 0) { daysToSubtract += 7; } return(monthStartDate.Date == DateTime.MinValue.Date ? monthStartDate : monthStartDate.AddDays(-daysToSubtract)); }
internal static DateTime GetCellDateForViewLevel(DateTime date, CalendarDisplayMode displayMode) { switch (displayMode) { case CalendarDisplayMode.YearView: return(CalendarMathHelper.GetFirstDateOfMonth(date)); case CalendarDisplayMode.DecadeView: return(CalendarMathHelper.GetFirstDateOfYear(date)); case CalendarDisplayMode.CenturyView: return(CalendarMathHelper.GetFirstDateOfDecade(date)); default: return(date); } }
internal static DateTime GetFirstDateForCurrentDisplayUnit(DateTime date, CalendarDisplayMode displayMode) { // NOTE: Ignore time part for calendar calculations. date = date.Date; switch (displayMode) { case CalendarDisplayMode.YearView: return(CalendarMathHelper.GetFirstDateOfYear(date)); case CalendarDisplayMode.DecadeView: return(CalendarMathHelper.GetFirstDateOfDecade(date)); case CalendarDisplayMode.CenturyView: return(CalendarMathHelper.GetFirstDateOfCentury(date)); default: return(CalendarMathHelper.GetFirstDateOfMonth(date)); } }
internal static bool IsCalendarViewChanged(DateTime displayDate, DateTime newDisplayDate, CalendarDisplayMode displayMode) { // NOTE: Ignore time part for calendar calculations. displayDate = displayDate.Date; newDisplayDate = newDisplayDate.Date; switch (displayMode) { case CalendarDisplayMode.YearView: return(displayDate.Year != newDisplayDate.Year); case CalendarDisplayMode.DecadeView: return(CalendarMathHelper.GetFirstDateOfDecade(displayDate) != CalendarMathHelper.GetFirstDateOfDecade(newDisplayDate)); case CalendarDisplayMode.CenturyView: return(CalendarMathHelper.GetFirstDateOfCentury(displayDate) != CalendarMathHelper.GetFirstDateOfCentury(newDisplayDate)); default: return(CalendarMathHelper.GetFirstDateOfMonth(displayDate) != CalendarMathHelper.GetFirstDateOfMonth(newDisplayDate)); } }
private static DateTime GetLastDateOfMonthView(DateTime date) { return(CalendarMathHelper.GetFirstDateOfMonth(date).AddMonths(1).AddDays(-1)); }