Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<DateTime> NextDays(this DateTime actual, int daysAhead, List<DateTime> list = null)
- {
- if (list == null)
- list = new List<DateTime>();
- list.Add(actual);
- if (daysAhead == 0)
- return list;
- if (daysAhead > 0)
- return NextDays(actual.AddDays(1), --daysAhead, list);
- return NextDays(actual.AddDays(-1), ++daysAhead, list);
- }
- public static List<DateTime> NextWeekDays(this DateTime actual, int daysAhead, List<DateTime> list = null, bool? backwards = null)
- {
- if (list == null)
- list = new List<DateTime>();
- if (backwards == null)
- backwards = daysAhead < 0;
- if (actual.DayOfWeek == DayOfWeek.Saturday)
- actual = actual.AddDays(backwards.Value ? -1 : 2);
- else if (actual.DayOfWeek == DayOfWeek.Sunday)
- actual = actual.AddDays(backwards.Value ? -2 : 1);
- list.Add(actual);
- if (daysAhead == 0)
- return list;
- if (daysAhead > 0)
- return NextWeekDays(actual.AddDays(1), --daysAhead, list, backwards);
- return NextWeekDays(actual.AddDays(-1), ++daysAhead, list, backwards);
- }
Add Comment
Please, Sign In to add comment