Extract unique months from date range

I have a date range, (@calendar_start@calendar_end).

start will always be the first of the month and end will always be the last of the month. They won’t always share the same month.

When looping over this range, I would like to stop at the end of the month, fill in the remaining filler dates (end of the week) and start a new list of the next month (I’m building a calendar as a unordered list).

What is the best method to exit, complete month view and continue on with the loop for the remaining time?

Hope I’m somewhat clear enough…*it’s a little late.

Thanks.

Here’s what I came up with on my own, as a helper. Would appreciate criticisms


if (day+1).month != day.month
  calendar_end = []
  if (day+1).month <= calendar_end_date.month
    (6-day.wday).times do |count|
      calendar_end << '<li class="month_end"></li>'
    end

    calendar_end << '</ul><ul class="project_calendar">'

    (day.wday+1).times do
      calendar_end << '<li class="month_lead"></li>'
    end
  end
    return raw calendar_end.join("")      
end