Googlemail
(Googlemail)
1
I have a table with dates
start => 2013-02-04
end => 2013-02-13
I can count all days:
def self.business_days(start, end)
((start)…(end)).select {|d| (1…5).include?(d.wday) }.size
end
=> 8…o.k.
but we have two cweek(s)
in the above ex. => first cweek 5 business days (Mo - Fr),
second 3 (Mo - Wed)
I want to store the cweek + business days per week like this
week_id, days
=> 60 , 5
=> 61, 3
Tried
(start_week_id…end_week_id).each { |week|
Model.create(:week_id => week, :days => ???
end
Need some inspiration how to find out the days per given cweek
Thanks for support
Werner
Do you have the starting date of each week? or are these weeks in the
standard year, i.e., the week_num will be correct?
If so, calculating the number of days per week in the span might go
something like this pseudo-code:
for each date from start_date to end_date
if date is a weekday, then
increment days_worked_this_week[date.week_num]
end if
end for
days_worked_this_week will be an array with the accumulated days
worked in that week.
Googlemail
(Googlemail)
3
Thanks for your input…
I will check that…
Werner
Ben.Curtis
(Ben Curtis)
4
You might find the business_time and holidays gems useful.