As the garbled question says I'm basically looking for a tidier way to do the following snip. (its used in a calendar for availability matching)
//TODO: Optimize elseif Statement
if (date.Year == now.Year && date.Month == now.Month && day == now.Day)
{
daysXhtml.Append("<td class=\"today\">" + day.ToString() + "</td>");
}
else if (((day == SelectedDate.Day)
|| (day != SelectedDate.Day && ((day == SelectedDate.AddDays(1).Day || (SelectedDate.Day > 3 && day == SelectedDate.AddDays(-1).Day)) && (day != SelectedDate.AddDays(2).Day || (SelectedDate.Day > 3 && day != SelectedDate.AddDays(-2).Day) || day != SelectedDate.AddDays(3).Day || (SelectedDate.Day > 3 && day != SelectedDate.AddDays(-3).Day))))
|| (day != SelectedDate.Day && ((day == SelectedDate.AddDays(2).Day || (SelectedDate.Day > 3 && day == SelectedDate.AddDays(-2).Day)) && (day != SelectedDate.AddDays(3).Day || (SelectedDate.Day > 3 && day != SelectedDate.AddDays(-3).Day) || day != SelectedDate.AddDays(1).Day || (SelectedDate.Day > 3 && day != SelectedDate.AddDays(-1).Day))))
|| (day != SelectedDate.Day && ((day == SelectedDate.AddDays(3).Day || (SelectedDate.Day > 3 && day == SelectedDate.AddDays(-3).Day)) && (day != SelectedDate.AddDays(2).Day || (SelectedDate.Day > 3 && day != SelectedDate.AddDays(-2).Day) || day != SelectedDate.AddDays(1).Day || (SelectedDate.Day > 3 && day != SelectedDate.AddDays(-1).Day)))))
&& ((float)endprice > 0) && (SelectedDate.Month == date.Month))
{}
Your ears and eyes can bleed now ;o)
Just to clarify... SelectedDate is the date passed to the calendar. And Day is Day in the month. (while loop day <= days) var date = new DateTime(SelectedDate.Year, SelectedDate.Month, 1);
Basically I'm passing a Date (say 27/11/2010 which is SelectedDay) which I need to test it. Is the SelectedDay the Current Calendar day being added to the string. If its not then if i add a day to the Selected Day does it match, then if not, two days, and again, three days.
But because its a date I have to check if its over day 3 before allowing it to check if it can match the day minus 3 (or the end of the last month will be used to mark the end of this month)
Answer
I used the following Syntax in the end.
DateTime currentCalDate = DateTime.Parse(String.Format("{0}/{1}/{2}", day, SelectedDate.Month, SelectedDate.Year));
int daysToAdd = (currentCalDate.Day + 3 < days) ? 3 : 0;
int daysToDeduct = (currentCalDate.Day - 3 > 0) ? -3 : 0;
And
else if ((SelectedDate >= currentCalDate.AddDays(daysToDeduct) && SelectedDate <= currentCalDate.AddDays(daysToAdd)) && ((float)endprice > 0))
:o)