From d29208ca838deb0ba7e669318a411625281cfcd4 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 11 Jul 2023 09:26:11 +0300 Subject: [PATCH] fix weekly --- app/helpers/timeline_helper.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/timeline_helper.rb b/app/helpers/timeline_helper.rb index a1cc0d3..29859bc 100644 --- a/app/helpers/timeline_helper.rb +++ b/app/helpers/timeline_helper.rb @@ -29,21 +29,21 @@ module TimelineHelper max = max_days - started_days(member) distance > max ? max : distance end + + # weekly occupany, hash containing weeks to number of volunteer mapping def weekly data = {} - week = 0 - while( week < @weeks ) do + month_start = Date.today.at_beginning_of_month + ( 0 ... @weeks ).each do |week| data[ week ] = -1 - start_week = Date.today.at_beginning_of_month + week.weeks - end_week = Date.today.at_beginning_of_month + (week + 1).weeks + end_week = month_start + week.weeks @members.each do |mem| next unless mem.arriving next unless mem.leaving - next if mem.arriving > start_week - next if mem.leaving < end_week + next if mem.leaving <= end_week + next if mem.arriving >= (end_week - 7.days) data[ week ] += 1 end - week += 1 end data end