Наконец, я придумал довольно простой метод в ruby
def session_dates(date, weekdays_arr, number_of_working_days)
result = []
while result.size < number_of_working_days
if weekdays_arr.include? date.wday
result << date
end
date += 1
end
result
end
, вызвав такой метод
start_date = Date.today.beginning_of_month
session_days_in_week = [0,1,2,3,4,5,6] # week starts from 0(Sunday)
result = session_dates(start_date, session_days_in_week, 20)
Я могу получить все даты в будние дни в output
[
[ 0] Mon, 01 Jun 2020,
[ 1] Tue, 02 Jun 2020,
[ 2] Wed, 03 Jun 2020,
[ 3] Thu, 04 Jun 2020,
[ 4] Fri, 05 Jun 2020,
[ 5] Sat, 06 Jun 2020,
[ 6] Sun, 07 Jun 2020,
[ 7] Mon, 08 Jun 2020,
[ 8] Tue, 09 Jun 2020,
[ 9] Wed, 10 Jun 2020,
[10] Thu, 11 Jun 2020,
[11] Fri, 12 Jun 2020,
[12] Sat, 13 Jun 2020,
[13] Sun, 14 Jun 2020,
[14] Mon, 15 Jun 2020,
[15] Tue, 16 Jun 2020,
[16] Wed, 17 Jun 2020,
[17] Thu, 18 Jun 2020,
[18] Fri, 19 Jun 2020,
[19] Sat, 20 Jun 2020
]
и, очевидно, последний элемент в массиве результатов - end_date.