Business days

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

On Fri, Feb 8, 2013 at 11:35 AM, Werner
[email protected] wrote:

=> 8…o.k.

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.

Thanks for your input…
I will check that…
Werner

Am Samstag, 9. Februar 2013 23:46:20 UTC+1 schrieb tamouse:

You might find the business_time and holidays gems useful.


Benjamin C.
http://honeybadger.io - Modern error tracking for Rails apps

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs