fork(1) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. class LockedDate
  8. {
  9. public bool IsYearly;
  10. public DateTime Date;
  11. }
  12.  
  13. static List<DateTime> GetDateRange(List<LockedDate> source, DateTime start, DateTime end)
  14. {
  15. if (start > end)
  16. throw new ArgumentException("Start must be before end");
  17.  
  18. var ts = end - start;
  19. var dates = Enumerable.Range(0, ts.Days)
  20. .Select(i => start.AddDays(i))
  21. .Where(d => source.Any(ld => ld.Date == d
  22. || (ld.IsYearly && ld.Date.Month == d.Month && ld.Date.Day == d.Day)));
  23. return dates.ToList();
  24. }
  25.  
  26. public static void Main()
  27. {
  28. DateTime start = new DateTime(2013, 01, 22);
  29. DateTime end = new DateTime(2015, 02, 23);
  30. var lockDates = new List<LockedDate> {
  31. new LockedDate { Date = new DateTime(2013, 12, 25), IsYearly = true } ,
  32. new LockedDate { Date = new DateTime(2011, 12, 02), IsYearly = false } ,
  33. new LockedDate { Date = new DateTime(2013, 03, 25), IsYearly = false }
  34. };
  35. var range = GetDateRange(lockDates, start, end);
  36. foreach(DateTime dt in range)
  37. Console.WriteLine(dt.ToString("dddd, MMMM dd, yyyy"));
  38. }
  39. }
Success #stdin #stdout 0.04s 33992KB
stdin
Standard input is empty
stdout
Monday, March 25, 2013
Wednesday, December 25, 2013
Thursday, December 25, 2014