week-of-month
week-of-month copied to clipboard
suggestion about use of week_of_month and general_week_of_month
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?
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.