week-of-month
week-of-month copied to clipboard
How to not start week in friday?
Could you put an option where the week should only start if you have a Wednesday?
Something like that
def get_month_week(date_or_time, start_day = :monday)
date = date_or_time.to_date
month_start = Date.new(date.year, date.month, 1)
week_start_format = start_day == :monday ? '%U' : '%W'
week_of_month = date.week_of_month
month_start_num = month_start.strftime(week_start_format).to_i
month_start_num += 1 if month_start.wday > 4 # Skip first week if doesn't contain a Thursday
month_week_index = date.strftime(week_start_format).to_i - month_start_num
month_week_index
end