From 417644e764a74f488847a0b6f15b5236c5c93a6b Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 27 Aug 2023 22:58:33 +0300 Subject: [PATCH] use start of week not month --- app/controllers/timeline_controller.rb | 2 +- app/helpers/timeline_helper.rb | 13 ++++++++----- app/views/timeline/index.haml | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index 8c9f1d2..413211d 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -4,7 +4,7 @@ class TimelineController < ApplicationController @weeks = (params[:weeks] || "12").to_i @members = Member.visible_scope. where("leaving > ? " , Date.today). - where("arriving < ? " , Date.today.at_beginning_of_month + @weeks.weeks). + where("arriving < ? " , helpers.start_day + @weeks.weeks). order(:arriving). page(1).per(50) end diff --git a/app/helpers/timeline_helper.rb b/app/helpers/timeline_helper.rb index 0e23752..c77c925 100644 --- a/app/helpers/timeline_helper.rb +++ b/app/helpers/timeline_helper.rb @@ -9,22 +9,25 @@ module TimelineHelper def max_days @weeks * 7 end + def start_day + Date.today.at_beginning_of_week - 1.week + end # number of days from start of month to start of stay def started_days(member) return 0 unless member.arriving - return 0 if member.arriving < Date.today.at_beginning_of_month - distance = (member.arriving - Date.today.at_beginning_of_month).to_i + return 0 if member.arriving < start_day + distance = (member.arriving - start_day).to_i distance > max_days ? max_days : distance end def left_max - Date.today.at_beginning_of_month + 3.months + start_day + 3.months end # amount of days of the stay, maxed at the number fo weeks shown def stay_days(member) return 0 unless member.leaving start = member.arriving - start = Date.today.at_beginning_of_month if member.arriving < Date.today.at_beginning_of_month + start = start_day if member.arriving < start_day distance = ( member.leaving - start ).to_i max = max_days - started_days(member) distance > max ? max : distance @@ -32,7 +35,7 @@ module TimelineHelper # weekly occupany, hash containing weeks to number of volunteer mapping def weekly - month_start = Date.today.at_beginning_of_month + month_start = start_day ( 0 ... @weeks ).collect do |week| amount = -1 start_week = month_start + week.weeks diff --git a/app/views/timeline/index.haml b/app/views/timeline/index.haml index 3684a7a..a2c255f 100644 --- a/app/views/timeline/index.haml +++ b/app/views/timeline/index.haml @@ -10,7 +10,7 @@ %tr - (0...@weeks).each do |week| %td{colspan: 7 , class: bg_for(week + 2) } - = small_date(Date.today.at_beginning_of_month + week.weeks) + = small_date(start_day + week.weeks) %tr - weekly.each_with_index do |amount , week | %td{colspan: 7, class: bg_for(week + 2) , style: "width: #{week_pixels}px;"}= amount