Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Extension */
- public static DateTime AddBusinessDays(this DateTime current, int days, IEnumerable<DateTime> holidays = null)
- {
- var sign = Math.Sign(days); // if (days == 0) return 0 , if (days > 0) return 1 , if (days < 0) return -1
- var unsignedDays = Math.Abs(days);
- for (var i = 0; i < unsignedDays; i++)
- {
- do
- {
- current = current.AddDays(sign);
- }
- while (current.DayOfWeek == DayOfWeek.Saturday
- || current.DayOfWeek == DayOfWeek.Sunday
- || (holidays != null && holidays.Contains(current.Date))
- );
- }
- return current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement