I want to return an array of dates, between two dates, either by weekly, bi-weekly or monthly. To keep it simply, I'll focus on weekly and monthly.
today = Date.today
# Not what I want but this shows all the days for the range:
(today.beginning_of_year..today.end_of_year).map { |date| date }
# Weekly
# I'm not comfortable hardcoding "7" but it MAY work.
# The same for by-weekly: 14
(today.beginning_of_year..today.end_of_year).step(7).map { |date| date }
I could get away with the above but let's look at monthly.
[..]
(today.beginning_of_year..today.end_of_year).step(31).map { |date| date }
I've hardcoded 31
. Not all months has 31 days. How to cater for months with less than 31 days? What's the best way to approach this. The aim is to return an array of dates, based on an interval (weekly, monthly etc) within a date range.
Has this been answered? Where? Thanks.