24namespace DateUtilities {
28using QuantLib::Weekday;
32 Date endOfMonth = Date::endOfMonth(Date(1, m, y));
33 Weekday lastWeekDayOfTheMonth = endOfMonth.weekday();
34 auto lastDayOfMonth = endOfMonth.dayOfMonth();
35 if (lastWeekDayOfTheMonth >= dayOfWeek) {
36 return Date(lastDayOfMonth - (lastWeekDayOfTheMonth - dayOfWeek), m, y);
38 return Date(lastDayOfMonth - 7 + (dayOfWeek - lastWeekDayOfTheMonth), m, y);
helper functions for date operations
Date lastWeekday(Weekday dayOfWeek, Month m, Year y)