Specific function for calendars

This is simpler:

start = DateObject[{2017, 6, 26}];
end = DateObject[{2017, 9, 1}];

Select[DateRange[start, end], 
  MatchQ[DayName[#], Monday | Tuesday | Friday] &][[;; 10]]

Mathematica graphics

DayRange is as close as it comes to a built in function with this purpose. It can select all weekdays in a range of dates, for example:

DayRange[start, end, "Weekday"]

Ideally, we'd be able to write something like

DayRange[start, end, Monday | Tuesday | Friday]

but this is not supported yet, which is why I had to make it slightly more complicated in my solution.

If selecting the end date is a problem we have to iterate. Check one date, is it a Monday, Tuesday or Friday? Add it to the list. Check the next date, and so on. Here is what an iterative solution could look like:

list = {};
date = DateObject[{2017, 6, 26}];
While[
 Length[list] < 10,
 If[
  MatchQ[DayName[date], Monday | Tuesday | Friday],
  AppendTo[list, date]
  ];
 date = DayPlus[date, 1];
 ]
list

Mathematica graphics


I have created two functions, but these have been quite extensive:

f[initialDate_, nDays_, week_] := 
 With[{group = <|Sunday -> 1, Monday -> 2, Tuesday -> 3, 
     Wednesday -> 4, Thursday -> 5, Friday -> 6, Saturday -> 7|>}, 
  Drop[Flatten[
     NestList[# + 7 &, group[#] & /@ week - First[group[#] & /@ week],
       IntegerPart[
       nDays/Length[
         group[#] & /@ week - First[group[#] & /@ week]]]]], 
    nDays - Length[
      Flatten[NestList[# + 7 &, 
        group[#] & /@ week - First[group[#] & /@ week], 
        IntegerPart[
         nDays/Length[
           group[#] & /@ week - First[group[#] & /@ week]]]]]]] + 
   DateValue[DateObject[initialDate], "Day"]]

allDays[initialDate_, nDays_, week_] := 
 If[f[initialDate, nDays, week][[#]] <= 
     QuantityMagnitude[
      With[{year = DateValue[DateObject[initialDate], "Year"], 
        month = DateValue[DateObject[initialDate], "Month"]}, 
       DateDifference[{year, month}, 
        If[month == 12, {year + 1, 1}, {year, month + 1}]]]], 
    f[initialDate, nDays, week][[#]], 
    f[initialDate, nDays, week][[#]] - 
     QuantityMagnitude[
      With[{year = DateValue[DateObject[initialDate], "Year"], 
        month = DateValue[DateObject[initialDate], "Month"]}, 
       DateDifference[{year, month}, 
        If[month == 12, {year + 1, 1}, {year, month + 1}]]]]] & /@ 
  Range[nDays]

allDays[{2017, 6, 26}, 10, {Monday, Tuesday, Friday}]

{26,27,30,3,4,7,10,11,14,17}