I have a daterange (from, to) that i want loop through an different intervals (daily, weekly, monthly, ...)
How can i loop through this dateranges?
Update
Thanks for your answers, i came up with the following:
interval = 'week' # month, year
start = from
while start < to
stop = start.send("end_of_#{interval}")
if stop > to
stop = to
end
logger.debug "Interval from #{start.inspect} to #{stop.inspect}"
start = stop.send("beginning_of_#{interval}")
start += 1.send(interval)
end
This will loop through a date range with intervals week, month or year and respects the beginning and end of the given interval.
Since i did not mention this in my question i choosed the answer that pushed me into the right direction.