week-of-month icon indicating copy to clipboard operation
week-of-month copied to clipboard

How to not start week in friday?

Open HAPTORE opened this issue 4 years ago • 1 comments

Could you put an option where the week should only start if you have a Wednesday?

HAPTORE avatar Dec 11 '20 18:12 HAPTORE

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

HAPTORE avatar Dec 11 '20 18:12 HAPTORE