I'm creating a way to organize some daily appointments.
I am a teacher and I have groups of students rotating for short periods. Sometimes 2 days a week, other times 3 days a week, ...
I am creating a way to define the days that I will have my appointments.
Below I determine the date of the first day of class and the number of days to finish the course:
date1 = {2017,6,26}; nDays=10;
Below I determine the numerical starting day of class and what is the day of the week:
day1=DateValue[DateObject[date1],"Day"]
dayName=DateValue[DateObject[date1],"DayName"]
26
Monday
Having the initial date I check how many days the current month has:
splitDate =
QuantityMagnitude[With[{year=DateValue[DateObject[date1],"Year"],
month = DateValue[DateObject[date1],"Month"]},
DateDifference[{year,month},If[month==12, {year+1,1}, {year,month+1}]]]]
30
Below I determine the days of the week that I will teach:
week = {Monday,Tuesday,Friday};
Below I associated the days of the week by numbers to get the differences between Sunday, Monday, ...
group=<|Sunday→1,Monday->2,Tuesday->3,
Wednesday->4,Thursday->5,Friday->6,Saturday->7|>;
firstWeek=group[#]&/@week-First[group[#]&/@week]
{0,1,4}
Below I defined the first week and created the other weeks according to the number of days I will teach. But it will always exceed the number of days to teach:
list1=Flatten[NestList[#+7&,firstWeek,IntegerPart[nDays/Length[firstWeek]]]]
{0,1,4,7,8,11,14,15,18,21,22,25}
Below I delete the days that are left ...
stepDays=Drop[list1,nDays-Length[list1]]
{0,1,4,7,8,11,14,15,18,21}
Below I create the dates according to the first day:
allDays=stepDays+day1
If[allDays[[#]]<=splitDate,allDays[[#]],allDays[[#]]-splitDate]&/@Range[nDays]
{26,27,30,33,34,37,40,41,44,47}
{26,27,30,3,4,7,10,11,14,17}
After all these steps, the question is this:
Is there any specific function for this type of day count? Or do I have to synthesize all these steps and create a function created by myself?