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

suggestion about use of week_of_month and general_week_of_month #28

Open
DevChristopher opened this issue Jun 12, 2018 · 1 comment
Open

Comments

@DevChristopher
Copy link

DevChristopher commented Jun 12, 2018

i have suggestion about function week_of_month and general_week_of_month.

for example, Jun. 2018, starts with friday(2018,6,1) and it is 5th week of May.

in this code, it shows incorrect week number.

Date.new(2018,6,6).week_of_month  #it return 2 but 1 is correct.

there is solution to use 'general_week_of_month' but this function return incorrect value if
date is "2018,5,1"

i avoided this issue using below code

if (date.week_split[0].count{|e| e == nil} > 2) #if there is three days of previous month
   date.general_week_of_month
else
   date.week_of_month
end

is there better solution?

@DevChristopher DevChristopher changed the title nice code. you saved my time. suggestion about use of week_of_month and general_week_of_month Jun 14, 2018
@sachin87
Copy link
Owner

sachin87 commented Jun 28, 2018

Date.new(2018,6,6).week_of_month returns 2 because this date lies in second week of June.
We assume week starts from Sunday and ends at Saturday. 1st of June is on friday, and thus only 1 and 2 june lies in first week.

If you want to Monday to be starting day of week then set WeekOfMonth.configuration.monday_active = true in your code.

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

2 participants