diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index 912fb496b98f0ac1ce0e657bb5ea3da79e6a337b..8f40c0baed73aabf8d0445a07d3d73ab6400d9d0 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -156,7 +156,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord title: "#{title} #{subtitle}", url: url, description: summary, - all_day: (from_hour.nil? && to_hour.nil?) + all_day: all_day? ) end @@ -172,15 +172,25 @@ class Communication::Website::Agenda::Event < ApplicationRecord end def to_time - if to_day.nil? - to_hour.nil? ? nil # Pas de fin, ni jour ni heure - : date_and_time(from_day, to_hour) # Heure de fin, donc on se base sur le jour de début - elsif to_day.present? - to_hour.nil? ? to_day.to_time # Jour de fin seul - : date_and_time(to_day, to_hour) # Jour et heure de fin + if to_day.nil? && to_hour.nil? + # Pas de fin + nil + elsif to_day.nil? && to_hour.present? + # Heure 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 end + def all_day? + from_hour.nil? && to_hour.nil? + end + def date_and_time(date, time) Time.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone) end