SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    976
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    976
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what I came up with on my own, as a helper. Would appreciate criticisms

    Code Ruby:
    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
    your brain reacts in the same way whether you are
    looking at something or thinking about it...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •