Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to not start week in friday? #34

Open
HAPTORE opened this issue Dec 11, 2020 · 1 comment
Open

How to not start week in friday? #34

HAPTORE opened this issue Dec 11, 2020 · 1 comment

Comments

@HAPTORE
Copy link

HAPTORE commented Dec 11, 2020

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

@HAPTORE
Copy link
Author

HAPTORE commented Dec 11, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant