From 96285c71f8c5bd38fee661a95c6a42b095cf0acd Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 28 Dec 2023 10:09:18 +0100 Subject: [PATCH] fix --- .../website/agenda/event/with_cal.rb | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/app/models/communication/website/agenda/event/with_cal.rb b/app/models/communication/website/agenda/event/with_cal.rb index 48df9eafb..450d395dc 100644 --- a/app/models/communication/website/agenda/event/with_cal.rb +++ b/app/models/communication/website/agenda/event/with_cal.rb @@ -3,37 +3,41 @@ module Communication::Website::Agenda::Event::WithCal def cal @cal ||= AddToCalendar::URLs.new( - start_datetime: from_time, - end_datetime: to_time, + start_datetime: cal_from_time, + end_datetime: cal_to_time, timezone: timezone.name, + all_day: cal_all_day, title: "#{title} #{subtitle}", url: url, - description: summary, - all_day: (from_hour.nil? && to_hour.nil?) + description: summary ) end protected - def from_time + def cal_from_time from_hour.nil? ? from_day.to_time : date_and_time(from_day, from_hour) end - def to_time - if to_day.nil? && to_hour.nil? - # Pas de fin - nil - elsif to_day.nil? && to_hour.present? - # Heure de fin sans jour de fin, donc on se base sur le jour de début - date_and_time(from_day, to_hour) - elsif to_day.present? && to_hour.nil? - # Jour de fin seul - to_day.to_time - elsif to_day.present? && to_hour.nil? - # Jour et heure de fin - date_and_time(to_day, to_hour) - end + def cal_to_time + to_day.nil? ? cal_to_time_with_no_end_day + : cal_to_time_with_end_day + end + + def cal_all_day + from_hour.nil? && to_hour.nil? + end + + # Ce cas n'est plus possible depuis la résolution #1386 + def cal_to_time_with_no_end_day + to_hour.nil? ? nil # Pas de fin + : date_and_time(from_day, to_hour) # Heure de fin sans jour de fin, donc on se base sur le jour de début + end + + def cal_to_time_with_end_day + to_hour.nil? ? to_day.to_time + 1.hour # Jour de fin seul, on ajoute 1 heure pour éviter les événements sans durée + : date_and_time(to_day, to_hour) # Jour et heure de fin end def timezone -- GitLab