Guest User

Untitled

a guest
Mar 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public static List<DateTime> NextDays(this DateTime actual, int daysAhead, List<DateTime> list = null)
  2. {
  3. if (list == null)
  4. list = new List<DateTime>();
  5.  
  6. list.Add(actual);
  7.  
  8. if (daysAhead == 0)
  9. return list;
  10.  
  11. if (daysAhead > 0)
  12. return NextDays(actual.AddDays(1), --daysAhead, list);
  13.  
  14. return NextDays(actual.AddDays(-1), ++daysAhead, list);
  15. }
  16.  
  17. public static List<DateTime> NextWeekDays(this DateTime actual, int daysAhead, List<DateTime> list = null, bool? backwards = null)
  18. {
  19. if (list == null)
  20. list = new List<DateTime>();
  21. if (backwards == null)
  22. backwards = daysAhead < 0;
  23.  
  24. if (actual.DayOfWeek == DayOfWeek.Saturday)
  25. actual = actual.AddDays(backwards.Value ? -1 : 2);
  26. else if (actual.DayOfWeek == DayOfWeek.Sunday)
  27. actual = actual.AddDays(backwards.Value ? -2 : 1);
  28.  
  29. list.Add(actual);
  30.  
  31. if (daysAhead == 0)
  32. return list;
  33.  
  34. if (daysAhead > 0)
  35. return NextWeekDays(actual.AddDays(1), --daysAhead, list, backwards);
  36.  
  37. return NextWeekDays(actual.AddDays(-1), ++daysAhead, list, backwards);
  38. }
Add Comment
Please, Sign In to add comment