In order to obtain the weekends of a year you'd use something like this:
With[{first = Take[DateList[], 2]},
DayRange[first, DatePlus[first, {{1, "Year"}, {-1, "Day"}}], "Weekend"]]
What I try to find out is how to either formulate this query in order to extract all the dates which are the last weekends of each month or through post-processing of the result.
One problem that occurs is that there are months with four weekends and some with five. Another issue is the case of August where the last weekend is reaching into September.
Formulation of a possible algorithm (post-processing)
- Partition the list into sublists of size two and group every month
- If the length of month is 1 = length mod 4, extend this sublist with the first element of the next month
- Group all the last elements of the sublists
I'd know exactly how to do that in C/C++ but alas still lack enough Mathematica skills. Any help is welcome.