public DateTime GetFirstWorkingDay(int year, int month)
{
DateTime FirstBusinessDay = default(DateTime);
FirstBusinessDay = new DateTime(year, month, 1);
while (IsHoliday(FirstBusinessDay) ||
IsWeekEnd(FirstBusinessDay))
{
FirstBusinessDay =
FirstBusinessDay.AddDays(1);
}
return FirstBusinessDay;
}
private bool IsHoliday(DateTime date)
{
bool isHoliday = false;
//Jan
1st -- Holiday
if (date.Month == 1 && date.Day == 1)
isHoliday = true;
//July
4th -- Independence Day
if (date.Month == 7 && date.Day == 4)
isHoliday = true;
//LABOR
DAY -- 1st Monday in September
DateTime laborDay = new DateTime(date.Year, 9, 1);
DayOfWeek dayOfWeek = laborDay.DayOfWeek;
while (dayOfWeek != DayOfWeek.Monday)
{
laborDay = laborDay.AddDays(1);
dayOfWeek = laborDay.DayOfWeek;
}
if (date == laborDay.Date)
isHoliday = true;
return isHoliday;
}
private bool IsWeekEnd(DateTime date)
{
return date.DayOfWeek == DayOfWeek.Saturday
|| date.DayOfWeek == DayOfWeek.Sunday;
}
No comments:
Post a Comment