public static class DateTimeExtensions { public static bool IsWeekend(this DayOfWeek d) { return !d.IsWeekday(); } public static bool IsWeekday(this DayOfWeek d) { switch (d) { case DayOfWeek.Sunday: case DayOfWeek.Saturday: return false; default: return true; } } public static DateTime AddWorkdays(this DateTime d, int days) { // start from a weekday while (d.DayOfWeek.IsWeekday()) d = d.AddDays(1.0); for (int i = 0; i < days; ++i) { d = d.AddDays(1.0); while (d.DayOfWeek.IsWeekday()) d = d.AddDays(1.0); } return d; } }
Kullanımı
DateTime due = DateTime.Today.AddWorkdays(10);
// due in 10 workdays
No comment