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 2013-02-08 18:36
on 2013-02-09 23:47
On Fri, Feb 8, 2013 at 11:35 AM, Werner <webagentur.laude@googlemail.com> 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.
on 2013-02-11 08:54
Thanks for your input... I will check that.. Werner Am Samstag, 9. Februar 2013 23:46:20 UTC+1 schrieb tamouse:
on 2013-02-11 15:03
You might find the business_time and holidays gems useful. -- Benjamin Curtis http://honeybadger.io - Modern error tracking for Rails apps
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.