I'm working on a form where the user enters a date range and selects from a list of checkboxes a day/days of the week i.e Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and saturday.
Once the form is submitted I need a way to grab a list of dates between the two dates entered based upon the days that were chosen i.e All Mondays and Thursdays between the two dates given. I've looked through the docs but can't pin point how to do this efficiently i.e the ruby way.
fun one! :D
start_date = Date.today # your start
end_date = Date.today + 1.year # your end
my_days = [1,2,3] # day of the week in 0-6. Sunday is day-of-week 0; Saturday is day-of-week 6.
result = (start_date..end_date).to_a.select {|k| my_days.include?(k.wday)}
using the data above you'll get an array of all Mon/Tue/Weds between now and next year.