I would like to check, if a rendered day in a webcalendar-element is X-mas Eve or the first of January or another date of a year and if so, colour that date differently.
So if the day rendered is the third Monday in May, colour it differently. If it is X-mas eve, colour it differently and so forth.
All ive found so far is how to extract the day to a specific date. But I would like to do kinda the opposite. Has anyone done that and can offer some tips?
It's not really clear what you mean by "do kinda the opposite" but:
static IsThirdMondayInMay(DateTime date)
{
// The first X in a month is always in the range [1, 8)
// The second X in a month is always in the range [8, 15)
// The third X in a month is always in the range [15, 22)
return date.Month == 5 && date.DayOfWeek == DayOfWeek.Monday &&
date.Day >= 15 && date.Day < 22;
}
static IsChristmasEve(DateTime date)
{
return date.Month == 12 && date.Day == 24;
}
Or more generally for the last:
static MonthDayMatches(DateTime date, int month, int day)
{
return date.Month == month && date.Day == day;
}
then:
bool christmasEve = MonthDayMatches(date, 12, 24);
See more on this question at Stackoverflow