Thanks for your input... I will check that.. Werner Am Samstag, 9. Februar 2013 23:46:20 UTC+1 schrieb tamouse: > > On Fri, Feb 8, 2013 at 11:35 AM, Werner > <webagent...@googlemail.com<javascript:>> > wrote: > > 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. >
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/JfTaS45ZPlAJ. For more options, visit https://groups.google.com/groups/opt_out.